module Capistrano::Helpers::Runit

Public Instance Methods

control_service(service_name, command, arguments = '', _ignore_error = false) click to toggle source

def restart_service(service_name)

control_service(service_name, "restart")

end

# File lib/capistrano/helpers/runit.rb, line 28
def control_service(service_name, command, arguments = '', _ignore_error = false)
  return unless test "[ -h '#{runit_service_path(service_name)}/run' ]"
  execute :sv, "#{arguments} #{command} #{runit_service_path(service_name)}"
end
disable_service(service_name) click to toggle source
# File lib/capistrano/helpers/runit.rb, line 38
def disable_service(service_name)
  begin
    force_control_service(service_name, 'force-stop', '', true) # force-stop the service before disabling it
  rescue
  end
  within(runit_service_path(service_name)) do
    execute :rm, '-f ./run' if test "[ -h '#{runit_service_run_file(service_name)}' ]"
    execute :rm, '-f ./finish' if test "[ -h '#{runit_service_finish_file(service_name)}' ]"
  end
end
enable_service(service_name) click to toggle source
# File lib/capistrano/helpers/runit.rb, line 49
def enable_service(service_name)
  within(runit_service_path(service_name)) do
    execute :ln, "-sf #{runit_service_run_config_file(service_name)} ./run" if test "[ ! -h '#{runit_service_run_file(service_name)}' ]"
    execute :ln, "-sf #{runit_service_finish_config_file(service_name)} ./finish" if test "[ ! -h '#{runit_service_finish_file(service_name)}' ]"
  end
end
force_control_service(service_name, command, arguments, _ignore_error = false) click to toggle source

Will not check if the service exists before trying to force it down

# File lib/capistrano/helpers/runit.rb, line 34
def force_control_service(service_name, command, arguments, _ignore_error = false)
  execute :sv, "#{arguments} #{command} #{runit_service_path(service_name)}"
end
purge_service(service_name) click to toggle source
# File lib/capistrano/helpers/runit.rb, line 56
def purge_service(service_name)
  execute :rm, "-rf #{runit_service_path(service_name)}"
end
runit_app_services_control(command) click to toggle source

Any command sent to this function controls all services related to the app

# File lib/capistrano/helpers/runit.rb, line 5
def runit_app_services_control(command)
  return unless test("[ -h '#{runit_etc_service_app_symlink_name}' ]")
  execute :sudo, :sv, "#{command} #{runit_etc_service_app_symlink_name}"
end
runit_set_executable_files(service_name) click to toggle source
# File lib/capistrano/helpers/runit.rb, line 60
def runit_set_executable_files(service_name) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  if test("[ -f '#{runit_service_run_config_file(service_name)}' ]")
    execute :chmod, "775 #{runit_service_run_config_file(service_name)}"
  end
  if test("[ -f '#{runit_service_finish_config_file(service_name)}' ]")
    execute :chmod, "775 #{runit_service_finish_config_file (service_name)}"
  end

  if test("[ -f '#{runit_service_log_run_file(service_name)}' ]")
    execute :chmod, "775 #{runit_service_log_run_file(service_name)}"
  end

  if test("[ -d '#{runit_service_control_path(service_name)}' ]") # rubocop:disable Style/GuardClause
    execute :chmod, "775 -R #{runit_service_control_path(service_name)}"
  end
end