diff --git a/ssm b/ssm index 276ab77..48c92a3 100755 --- a/ssm +++ b/ssm @@ -170,7 +170,7 @@ svc() { anywait "$job_pid" "$service_stop_timeout" - # Cgroup stuff + # Cgroup stuff, experimental and pretty much deprecated. if cgroups; then if service_cgroup_cleanup; then cgroup_get_procs @@ -227,6 +227,7 @@ svc() { # We need to wait for the service to write down its pidfile 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" break } @@ -234,8 +235,23 @@ svc() { sleep 0.1 done + # Read the pid. read -r job_pid < "$service_pidfile" + # Fail if the pid is empty + [[ $job_pid ]] || { + printf 'Job pidfile is empty: %s\n' "$service_pidfile" >&2 + printf '98' > "$service_exit_file" + 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" + break + } + # We consider any termination of a service with its own pidfile # to be a failure anywait "$job_pid"; job_exit=127