Skip to content

Commit

Permalink
Add support for services with a delegate cgroup subhierarchy in check…
Browse files Browse the repository at this point in the history
…services + ignore services in machine.slice by default

This commit adds support for services with a delegate cgroup subhierarchy and introduces the `-m/-M` option to include or not services in `machine.slice` (default is no).

Parts of the patch are taken from #61 (comment) & #61 (comment)

Fixes #61
  • Loading branch information
Antiz96 committed Jul 15, 2024
1 parent c53a022 commit bb714da
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion admin/checkservices
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ RESTART=1 # restart services
SERIALIZE=0 # run in parallel
STATUS=1 # display status after systemctl
USER_SLICE=0 # act on users services
MACHINE_SLICE=0 # act on machine services

# print $* as an arrow line
arrow() {
Expand Down Expand Up @@ -113,7 +114,10 @@ get_broken_maps() {
for service in $(get_services); do
unit_path="$(systemctl --property ControlGroup --value show "$service")"
# hack to fix to systemd internal cgroup escaping on slice
unit_path="$(printf "$unit_path"|sed 's,\\x5c,\\,')"
unit_path="$(printf '%s' "$unit_path"|sed 's,\\x5c,\\,')"
# has Delegate Subgroup?
delegate_path="$(systemctl --property DelegateSubgroup --value show "$service")"
[[ -n ${delegate_path} ]] && unit_path="${unit_path}/${delegate_path}"
# get the right pidfile name
pidfile=''
for path in "$SYSTEMD_CGROUP_BASE_PATH$unit_path/cgroup.procs" \
Expand All @@ -123,6 +127,7 @@ get_broken_maps() {
[[ -z "$pidfile" ]] && error "Unable to find pid file for $service." && continue
# skip non system units
(( $USER_SLICE == 0 )) && [[ "$unit_path" =~ /user\.slice/ ]] && continue
(( $MACHINE_SLICE == 0 )) && [[ "$unit_path" =~ /machine\.slice/ ]] && continue
# parse pidfile
pids=( $(< "$pidfile") )
if (( "${#pids[*]}" == 0 )); then
Expand Down Expand Up @@ -248,6 +253,7 @@ usage() {
echo " -r/-R: restart (or not) services with updated files (default: $RESTART)" >&2
echo " -s/-S: display (or not) status of restarted service (default: $STATUS)" >&2
echo " -u/-U: act (or not) on services in users slice (default: $USER_SLICE)" >&2
echo " -m/-M: act (or not) on services in machine slice (default: $MACHINE_SLICE)" >&2
echo " -z/-Z: serialize (or not) action (default: $SERIALIZE)" >&2
exit 2
}
Expand All @@ -265,6 +271,7 @@ argparse() {
R) RESTART=0;; r) RESTART=1;;
S) STATUS=0;; s) STATUS=1;;
U) USER_SLICE=0;; u) USER_SLICE=1;;
M) MACHINE_SLICE=0;; m) MACHINE_SLICE=1;;
Z) SERIALIZE=0;; z) SERIALIZE=1;;
*) usage;;
esac
Expand Down

0 comments on commit bb714da

Please sign in to comment.