From 7e0df4a559c5c020906d3c70a0eb52bd399751f5 Mon Sep 17 00:00:00 2001 From: fbt Date: Mon, 5 Mar 2018 01:13:55 +0300 Subject: [PATCH] +#service_cgroup_cleanup Signed-off-by: fbt --- ssm | 19 +++++++++++++++++-- ssm.conf | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ssm b/ssm index 7843e0b..2c1b1ea 100755 --- a/ssm +++ b/ssm @@ -133,8 +133,8 @@ spawn() { ## Run the command and wait for it to die svc() { - declare job_pid job_exit job_success last_respawn fail_counter date counter - var job_pid job_exit job_success last_respawn fail_counter date counter + 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 svc::cleanup() { nullexec kill -n "$service_stop_signal" "$job_pid" @@ -142,6 +142,20 @@ svc() { anywait "$job_pid" "$service_stop_timeout" rm -f "$svc_pidfile" "$service_ready_flag" + # Cgroup stuff + if cgroups; then + if service_cgroup_cleanup; then + for p in "${service_cgroup_procs[@]}"; do + p == "$BASHPID" || { + nullexec kill -n "$service_cgroup_kill_signal" "$p" + anywait "$p" "$service_stop_timeout" & + } + done + + wait || die $? + fi + fi + die 0 }; trap 'svc::cleanup' TERM @@ -564,6 +578,7 @@ var service_cgroup_wait = 0 # Wait on all the members of the cgroup to exit when var service_cgroup_strict = 1 # Enable checking if the main service PID is in the correct cgroup before doing anythin with the service var service_cgroup_kill = 0 # Kill the entire cgroup when stopping the service. var service_cgroup_kill_signal = 15 # The signal to send to the stray cgroup members. +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. diff --git a/ssm.conf b/ssm.conf index 41a67c4..b959db7 100644 --- a/ssm.conf +++ b/ssm.conf @@ -44,3 +44,6 @@ ## stopping the service, and the signal to send: #service_cgroup_kill = 0 #service_cgroup_kill_signal = 15 + +# Clean up the cgroup when the service exits for any reason +#service_cgroup_cleanup = 0