Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for services with a delegate cgroup subhierarchy in checkservices + ignore services in machine.slice by default #79

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading