Commit fdf14513 authored by Seblu's avatar Seblu
Browse files

checkservice: improve display of errors and warnings

parent 3d6bee3c
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ if [[ -t 1 ]]; then
	c_title='\e[1;33m'
	c_svc='\e[1;31m'
	c_warn='\e[5;30;43m'
	c_error='\e[5;30;41m'
	c_rst='\e[m'
fi

@@ -97,11 +98,16 @@ declare -i pid=0
for svc in "${services[@]}"; do
	unit_path="$(systemctl -p ControlGroup show "$svc"|cut -f 2 -d=)"
	busname="$(systemctl -p BusName show "$svc"|cut -f 2 -d=)"
	tasks_path="$systemd_cgroup_base_path/$unit_path/tasks"
	[[ -e "$tasks_path" ]] || {
		echo "${c_error}** Unable to get pid of $svc: No tasks file: $tasks_path${c_rst}" >&2
		continue
	}
	# check if unit is in system slice
	[[ "$unit_path" =~ /user\.slice/ && ! "$user_slice" == true ]] && continue
	pids=( $(< "$systemd_cgroup_base_path/$unit_path/tasks") )
	if (( "${#pids[*]}" == 0 )); then
		echo "** Unable to get pid of $svc" >&2
		echo "${c_error}** Unable to get pid of $svc: Tasks file is empty${c_rst}" >&2
		continue
	fi
	deleted=''
@@ -150,9 +156,9 @@ fi

# warn if dbus was restart
if in_array dbus.service "${needy[@]}"; then
	echo "${c_warn}After dbus restart, you should run ${0##*/} twice${c_rst}"
	echo "${c_warn}After dbus restart, you should run ${0##*/} twice${c_rst}" >&2
	if [[ -n "$systemd_cmd" && -z $CHECKSERVICE_WAS_RESTARTED ]]; then
		echo "${c_warn}Doing it for you. No need to thanks me!${c_rst}"
		echo "${c_warn}Doing it for you. No need to thanks me!${c_rst}" >&2
		export CHECKSERVICE_WAS_RESTARTED=1
		exec "$0" "$@"
	fi