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

30
ssm
View File

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