Skip to content

Commit

Permalink
Merge pull request #78 from archlinux/ignore_services
Browse files Browse the repository at this point in the history
Add a configurable "ignored service" list to checkservices
  • Loading branch information
Antiz96 committed Jul 20, 2024
2 parents e727aa0 + 23d926c commit 55e6f07
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions admin/checkservices
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ STATUS=1 # display status after systemctl
USER_SLICE=0 # act on users services
MACHINE_SLICE=0 # act on machine services

# ignored service list
IGNORED_SERVICES=("getty@tty.*.service" "systemd-logind.service" "dbus-broker.service")

# print $* as an arrow line
arrow() {
printf "${C_BOLD}${C_BLUE}:: ${C_RESET}${C_BOLD}%s${C_RESET}\n" "$*"
Expand Down Expand Up @@ -102,7 +105,7 @@ confirm() {

# get running systemd services
get_services() {
systemctl --no-legend --full --type service --state running | tr -d '' | awk '{print $1}'
systemctl --no-legend --full --type service --state running | tr -d '' | awk '{print $1}' | grep -v $(printf -- '-e %s ' "${IGNORED_SERVICES[@]}")
}

# get systemd services with updated mapped files
Expand Down Expand Up @@ -254,14 +257,15 @@ usage() {
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
echo " -i 'service_name'.service: ignore a specific service (can be used multiple times)" >&2
exit 2
}

# parse command line arguments
# set options as global vars
argparse() {
local opt
while getopts 'AahFfLlPpRrSsUuZz' opt; do
while getopts 'AahFfLlPpRrSsUuZzi:' opt; do
case $opt in
A) AUTOCONFIRM=0;; a) AUTOCONFIRM=1;;
F) FAILED=0;; f) FAILED=1;;
Expand All @@ -272,6 +276,12 @@ argparse() {
U) USER_SLICE=0;; u) USER_SLICE=1;;
M) MACHINE_SLICE=0;; m) MACHINE_SLICE=1;;
Z) SERIALIZE=0;; z) SERIALIZE=1;;
i) if [[ "$OPTARG" == *.service ]]; then
IGNORED_SERVICES+=("$OPTARG")
else
usage
fi
;;
*) usage;;
esac
done
Expand Down

0 comments on commit 55e6f07

Please sign in to comment.