Skip to content

Commit 23d926c

Browse files
committed
Add a configurable "ignored service" list to checkservices
This commit aims to introduce an ignored service list that contains services that are known to cause parsing errors and/or issues when being restarted. Elements can be added to the list with the `-i "service_name".service` option (e.g. `checkservices -i sddm.service -i NetworkManager.service`) Show usage and exit if the `-i` argument does not finish with `.service` (to ensure a precise parsing and avoid unexpected filtering) Fixes #44
1 parent c53a022 commit 23d926c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

admin/checkservices

+12-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ SERIALIZE=0 # run in parallel
5555
STATUS=1 # display status after systemctl
5656
USER_SLICE=0 # act on users services
5757

58+
# ignored service list
59+
IGNORED_SERVICES=("getty@tty.*.service" "systemd-logind.service" "dbus-broker.service")
60+
5861
# print $* as an arrow line
5962
arrow() {
6063
printf "${C_BOLD}${C_BLUE}:: ${C_WHITE}%s${C_RESET}\n" "$*"
@@ -102,7 +105,7 @@ confirm() {
102105

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

108111
# get systemd services with updated mapped files
@@ -249,14 +252,15 @@ usage() {
249252
echo " -s/-S: display (or not) status of restarted service (default: $STATUS)" >&2
250253
echo " -u/-U: act (or not) on services in users slice (default: $USER_SLICE)" >&2
251254
echo " -z/-Z: serialize (or not) action (default: $SERIALIZE)" >&2
255+
echo " -i 'service_name'.service: ignore a specific service (can be used multiple times)" >&2
252256
exit 2
253257
}
254258

255259
# parse command line arguments
256260
# set options as global vars
257261
argparse() {
258262
local opt
259-
while getopts 'AahFfLlPpRrSsUuZz' opt; do
263+
while getopts 'AahFfLlPpRrSsUuZzi:' opt; do
260264
case $opt in
261265
A) AUTOCONFIRM=0;; a) AUTOCONFIRM=1;;
262266
F) FAILED=0;; f) FAILED=1;;
@@ -266,6 +270,12 @@ argparse() {
266270
S) STATUS=0;; s) STATUS=1;;
267271
U) USER_SLICE=0;; u) USER_SLICE=1;;
268272
Z) SERIALIZE=0;; z) SERIALIZE=1;;
273+
i) if [[ "$OPTARG" == *.service ]]; then
274+
IGNORED_SERVICES+=("$OPTARG")
275+
else
276+
usage
277+
fi
278+
;;
269279
*) usage;;
270280
esac
271281
done

0 commit comments

Comments
 (0)