make the procedure for killing child processes of services configurable

This commit is contained in:
William Hubbs 2017-09-14 11:40:26 -05:00
parent 2b0345165e
commit 6a5ca2ab36
2 changed files with 34 additions and 8 deletions

View File

@ -277,10 +277,33 @@ rc_tty_number=12
# Set this to YES if you want all of the processes in a service's cgroup
# killed when the service is stopped or restarted.
# This should not be set globally because it kills all of the service's
# child processes, and most of the time this is undesirable. Please set
# it in /etc/conf.d/<service>.
# Be aware that setting this to yes means all of a service's
# child processes will be killed. Keep this in mind if you set this to
# yes here instead of for the individual services in
# /etc/conf.d/<service>.
# To perform this cleanup manually for a stopped service, you can
# execute cgroup_cleanup with /etc/init.d/<service> cgroup_cleanup or
# rc-service <service> cgroup_cleanup.
# The process followed in this cleanup is the following:
# 1. send stopsig (sigterm if it isn't set) to all processes left in the
# cgroup immediately followed by sigcont.
# 2. Send sighup to all processes in the cgroup if rc_send_sighup is
# yes.
# 3. delay for rc_timeout_stopsec seconds.
# 4. send sigkill to all processes in the cgroup unless disabled by
# setting rc_send_sigkill to no.
# rc_cgroup_cleanup="NO"
# If this is yes, we will send sighup to the processes in the cgroup
# immediately after stopsig and sigcont.
#rc_send_sighup="NO"
# This is the amount of time in seconds that we delay after sending sigcont
# and optionally sighup, before we optionally send sigkill to all
# processes in the # cgroup.
# The default is 90 seconds.
#rc_timeout_stopsec="90"
# If this is set to no, we do not send sigkill to all processes in the
# cgroup.
#rc_send_sigkill="YES"

View File

@ -204,10 +204,13 @@ cgroup_cleanup()
local pids
pids="$(cgroup_get_pids)"
if [ -n "${pids}" ]; then
kill -s TERM "${pids}"
sleep 1
pids="$(cgroup_get_pids)"
[ -n "${pids}" ] &&
kill -s KILL "${pids}"
kill -s "${stopsig:-SIGTERM}" ${pids} 2> /dev/null
kill -s SIGCONT ${pids} 2> /dev/null
yesno "${rc_send_sighup:-no}" &&
kill -s SIGHUP ${pids} 2> /dev/null
sleep "${rc_timeout_stopsec:-90}"
yesno "${rc_send_sigkill:-yes}" &&
kill -s SIGKILL ${pids} 2> /dev/null
fi
eend 0
}