From 7afeb29bf28fa8e36edba2dc0507031ef37b7c1b Mon Sep 17 00:00:00 2001 From: fbt Date: Fri, 9 Mar 2018 07:19:18 +0300 Subject: [PATCH] Some ideas were dumb Signed-off-by: fbt --- ssm | 67 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/ssm b/ssm index 1f06c4e..438c880 100755 --- a/ssm +++ b/ssm @@ -410,6 +410,7 @@ result() { ## Start the service, write down the svc pid start() { service_running && return 3 + service_enabled && return 19 service_command is file || return 9 # Preform cgroup checks @@ -459,7 +460,6 @@ reload() { ## 3: Service is not running. stop() { if service_oneshot; then - service_enabled || return 3 return 7 else service_running || return 3 @@ -499,23 +499,29 @@ info() { info::item() { printf "%16s: %s\n" "$1" "$2"; } - status; _status_code = "$?" - case $_status_code in - (0) _status = 'running';; - (1) _status = 'down';; - (2) _status = 'success';; - (7) _status = 'stopped';; - (9) _status = "failed: $service_exit_last";; - (11) _status = "exited: $service_exit_last";; - (*) _status = 'unknown';; - esac - info::item Name "$service_name" + status; _status_code = "$?" if service_oneshot; then info::item Oneshot 'yes' + + case $_status_code in + (0) _status = 'success';; + (1) _status = 'not enabled';; + (9) _status = 'failed';; + (*) _status = 'unknown';; + esac else info::item Restart "$service_respawn" + + case $_status_code in + (0) _status = 'running';; + (1) _status = 'down';; + (7) _status = 'stopped';; + (9) _status = "failed: $service_exit_last";; + (11) _status = "exited: $service_exit_last";; + (*) _status = 'unknown';; + esac fi info::item Status "$_status" @@ -559,18 +565,14 @@ logs() { ## Status is a bit of a special case. It's talkative. status() { service_running && return 0 - service_enabled && return 2 + service_enabled && return 0 service_stopped && return 7 service_failed && return 9 service_exit_last is empty || return 11 - if service_oneshot; then - return 13 - else - return 1 - fi + return 1 } ## For use in scripts @@ -614,7 +616,8 @@ var service_pid \ rundir \ logdir \ action \ - _self + _self \ + res ## Internal defaults var flag_list_services = 0 @@ -953,7 +956,7 @@ service_workdir && { run_service_action "pre_$action" || die 13 "pre_$action failed!" # Run the main action -run_service_action "$action"; res=$? +run_service_action "$action"; res = "$?" case "$action" in stop) @@ -973,7 +976,8 @@ case "$action" in 9 "service_command does not exist: ${service_command[0]}" \ 13 "Failed to create temporary files for $service_name" \ 15 "Refusing to start $service_name: the service cgroup is not empty and \$service_cgroup_exclusive is set" \ - 17 "$service_name failed" + 17 "$service_name failed" \ + 19 "$service_name is already enabled" ;; reload) @@ -982,14 +986,19 @@ case "$action" in ;; status) - result "$res" \ - 0 "$service_name is running" \ - 2 "$service_name was successful" \ - 1 "$service_name is not running" \ - 7 "$service_name was stopped" \ - 9 "$service_name has failed with code: $service_exit_last" \ - 11 "$service_name has exited with code: $service_exit_last" \ - 13 "$service_name is not enabled" + if service_oneshot; then + result "$res" \ + 0 "$service_name was successful" \ + 1 "$service_name is not enabled" \ + 9 "$service_name has failed ($service_exit_last)" + else + result "$res" \ + 0 "$service_name is running" \ + 1 "$service_name is not running" \ + 7 "$service_name was stopped" \ + 9 "$service_name has failed with code: $service_exit_last" \ + 11 "$service_name has exited with code: $service_exit_last" + fi ;; esac