From 52f3117d3f176c3e34ab422897cd988aaeff9fd0 Mon Sep 17 00:00:00 2001 From: fbt Date: Mon, 5 Mar 2018 02:52:55 +0300 Subject: [PATCH] Remove stale pidfiles in the respawn loop Signed-off-by: fbt --- ssm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ssm b/ssm index 1a6caa0..a75527c 100755 --- a/ssm +++ b/ssm @@ -186,6 +186,14 @@ svc() { while true; do job_success = 0 # Needs to be reset + # Remove stale pidfiles some services may leave behind + # If a pidfile exists at this point in the code, it should be stale. + if service_pidfile_remove_stale; then + if ! svc_pidfile == "$service_pidfile"; then + service_pidfile is file && rm -f "$service_pidfile" + fi + fi + # Spawn the process and record the PID spawn "$@" & job_pid = "$!" @@ -369,6 +377,7 @@ start() { service_running && return 3 service_command is file || return 9 + # Preform cgroup checks if cgroups; then if service_cgroup_exclusive; then service_cgroup_procs is empty || return 15 @@ -591,6 +600,7 @@ var service_cgroup_kill_signal = 15 # The signal to send to the stray cgroup mem var service_cgroup_cleanup = 0 # Clean up the cgroup when the main PID exits. Uses service_cgroup_kill_signal. var service_success_exit = 0 # Array, takes exit codes that are to be treated as successful termination. var service_pidfile_timeout = 15 # How long to wait for unmanaged services to create their pidfiles. +var service_pidfile_remove_stale = 1 # Remove stale pidfiles from unmanaged services. # Global config var cgroups = 0 # Enable cgroup-related functions