Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make runit service's control commands (start/stop/restart/status) configurable #243

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def runit_send_signal(signal, friendly_name = nil)
end

def running?
cmd = safe_sv_shellout("#{sv_args}status #{service_dir_name}", returns: [0, 100])
cmd = safe_sv_shellout("#{sv_args}#{new_resource.service_status_command} #{service_dir_name}", returns: [0, 100])
!cmd.error? && cmd.stdout =~ /^run:/
end

Expand Down Expand Up @@ -153,15 +153,15 @@ def disable_service
end

def start_service
safe_sv_shellout!("#{sv_args}start #{service_dir_name}")
safe_sv_shellout!("#{sv_args}#{new_resource.service_start_command} #{service_dir_name}")
end

def stop_service
safe_sv_shellout!("#{sv_args}stop #{service_dir_name}")
safe_sv_shellout!("#{sv_args}#{new_resource.service_stop_command} #{service_dir_name}")
end

def restart_service
safe_sv_shellout!("#{sv_args}restart #{service_dir_name}")
safe_sv_shellout!("#{sv_args}#{new_resource.service_restart_command} #{service_dir_name}")
end

def restart_log_service
Expand Down
13 changes: 8 additions & 5 deletions libraries/resource_runit_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class RunitService < Chef::Resource::Service
property :check_script_template_name, String, default: lazy { service_name }
property :finish_script_template_name, String, default: lazy { service_name }
property :control_template_names, Hash, default: lazy { set_control_template_names }
property :status_command, String, default: lazy { "#{sv_bin} status #{service_name}" }
property :service_start_command, String, default: 'start'
property :service_stop_command, String, default: 'stop'
property :service_restart_command, String, default: 'restart'
property :service_status_command, String, default: 'status'
property :sv_templates, [true, false], default: true
property :sv_timeout, Integer
property :sv_verbose, [true, false], default: false
Expand Down Expand Up @@ -100,10 +103,10 @@ def after_created
find_resource(:service, new_resource.name) do # creates if it does not exist
provider Chef::Provider::Service::Simple
supports new_resource.supports
start_command "#{new_resource.sv_bin} start #{service_dir_name}"
stop_command "#{new_resource.sv_bin} stop #{service_dir_name}"
restart_command "#{new_resource.sv_bin} restart #{service_dir_name}"
status_command new_resource.status_command
start_command "#{new_resource.sv_bin} #{new_resource.service_start_command} #{service_dir_name}"
stop_command "#{new_resource.sv_bin} #{new_resource.service_stop_command} #{service_dir_name}"
restart_command "#{new_resource.sv_bin} #{new_resource.service_restart_command} #{service_dir_name}"
status_command "#{new_resource.sv_bin} #{new_resource.service_status_command} #{service_dir_name}"
action :nothing
end
end
Expand Down