From cd87cb46cdbdf3777989d02e721ae32bc705e5f3 Mon Sep 17 00:00:00 2001 From: fbt Date: Sun, 29 Nov 2026 09:43:29 +0000 Subject: [PATCH] This seems to work fine Signed-off-by: fbt --- ssm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ssm b/ssm index 48c92a3..5d0dab4 100755 --- a/ssm +++ b/ssm @@ -164,6 +164,8 @@ svc() { declare job_pid job_exit job_success last_respawn fail_counter date counter p var job_pid job_exit job_success last_respawn fail_counter date counter p + job_exit = 0 # Exit successfully by default + svc::cleanup() { #nullexec kill -n "$service_stop_signal" "$job_pid" nullexec "${service_stop_command[@]}" @@ -192,6 +194,10 @@ svc() { rm -f "$svc_pidfile" "$service_pidfile" "$service_ready_flag" + # Record the job exit code + printf '%d' "$job_exit" > "$service_exit_file" + + # Die die "$job_exit" }; trap 'svc::cleanup' TERM @@ -228,7 +234,7 @@ svc() { until service_pidfile is file; do (( counter >= service_pidfile_timeout*10 )) && { printf 'Timed out waiting for pidfile: %s' "$service_pidfile" >&2 - printf '127' > "$service_exit_file" + job_exit=127 break } counter++ @@ -241,14 +247,14 @@ svc() { # Fail if the pid is empty [[ $job_pid ]] || { printf 'Job pidfile is empty: %s\n' "$service_pidfile" >&2 - printf '98' > "$service_exit_file" + job_exit=127 break } # Fail if the pid doesn't look right printf -v _ '%d' "$job_pid" || { printf 'Job PID in %s seems to be malformed' "$service_pidfile" >&2 - printf '99' > "$service_exit_file" + job_exit=127 break } @@ -270,9 +276,6 @@ svc() { fail_counter++ fi - # Record the exit code - printf '%s' "$job_exit" > "$service_exit_file" - # Back off if the service exits too much AND too quickly. if ! service_respawn_force; then if (( fail_counter >= 3 )); then