+#service_cgroup_cleanup

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-03-05 01:13:55 +03:00
parent 8ae151b601
commit 7e0df4a559
2 changed files with 20 additions and 2 deletions

19
ssm
View File

@ -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.

View File

@ -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