cgroup cleanup

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-03-05 01:36:40 +03:00
parent 7e0df4a559
commit 42f42182ae

44
ssm
View File

@ -82,7 +82,7 @@ var() {
(is_fs_object) [[ -e \"\$_var\" ]];;
(is_file) [[ -f \"\$_var\" ]];;
(is_dir|is_directory) [[ -d \"\$_var\" ]];;
(is_empty) [[ -z \"\$_var\" ]];;
(is_empty) [[ -z \"\${_var[*]}\" ]];;
(*) die 71 \"Syntax error in ${var_function}!\";;
esac
@ -131,6 +131,14 @@ spawn() {
fi
}; readonly spawn;
cgroup_get_procs() {
if service_cgroup_path is dir; then
while read -r line; do
service_cgroup_procs += "$line"
done < "$cgroup_home/$service_cgroup_name/cgroup.procs"
fi
}; readonly -f cgroup_get_procs
## Run the command and wait for it to die
svc() {
declare job_pid job_exit job_success last_respawn fail_counter date counter p
@ -145,14 +153,18 @@ svc() {
# 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
cgroup_get_procs
wait || die $?
service_cgroup_procs is empty || {
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
@ -359,9 +371,7 @@ start() {
if cgroups; then
if service_cgroup_exclusive; then
if ! service_cgroup_empty; then
return 15
fi
service_cgroup_procs is empty || return 15
fi
fi
@ -594,8 +604,6 @@ var service_enabled = 0
var service_stopped = 0
var service_failed = 0
var service_nologs = 0
var service_cgroup_empty = 1
var service_cgroup_empty = 1
var service_respawn_flag = 0
var service_respawn_force = 0
@ -763,15 +771,7 @@ fi
# Check cgroups, if enabled
if cgroups; then
if service_cgroup_path is dir; then
while read -r line; do
service_cgroup_procs += "$line"
done < "$cgroup_home/$service_cgroup_name/cgroup.procs"
if (( ${#service_cgroup_procs[@]} )); then
service_cgroup_empty = 0
fi
fi
cgroup_get_procs
# If there's a service PID, check if it's in the service's cgroup
if service_cgroup_strict; then