diff --git a/ssm b/ssm index a4b74bd..7f9b091 100755 --- a/ssm +++ b/ssm @@ -26,12 +26,16 @@ svc() { declare job_pid svc::cleanup() { - "${service_command_stop[@]}" + kill -n "$service_stop_signal" "$job_pid" pid_wait "$job_pid" rm -f "$svc_pidfile" "$service_ready_flag" }; trap 'svc::cleanup' TERM + svc::reload() { + kill -n "$service_reload_signal" "$job_pid" + }; trap 'svc::reload' HUP + "$@" & job_pid=$! printf '%s' "$job_pid" > "$svc_pidfile" @@ -214,8 +218,8 @@ read_systemd_service() { case $key in (pidfile) service_pidfile=$value;; (execstart) eval "service_command=( $value )";; - (execstop) eval "service_command_stop=( $value )";; - (execreload) eval "service_command_reload=( $value )";; + (execstop) eval "stop() { $value; }";; + (execreload) eval "reload() { $value; }";; (restart) [[ $value == 'always' ]] && service_respawn=1;; esac ;; @@ -264,7 +268,12 @@ start() { ## Usually just sends HUP reload() { (( service_running )) || return 3 - "${service_command_reload[@]}" + + if (( service_managed )); then + kill -n 1 "$service_pid" + else + "${service_command_reload[@]}" + fi } ## Stop the service @@ -502,10 +511,6 @@ main() { fi fi - # The stop and reload commands need the service pid - default service_command_stop kill -n "$service_stop_signal" "$service_pid" - default service_command_reload kill -n "$service_reload_signal" "$service_pid" - # Maybe the service is enabled? if [[ -f "$service_enabled_flag" ]]; then # Yay, it is!