From 47381a6765cbfe5e0e2b5f576aa76903f939424c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Fri, 25 Jan 2019 19:43:00 +0100 Subject: [PATCH] Fix systemd --- usr/local/bin/systemd_check | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/usr/local/bin/systemd_check b/usr/local/bin/systemd_check index 0f5dfe0..98b1e63 100755 --- a/usr/local/bin/systemd_check +++ b/usr/local/bin/systemd_check @@ -74,13 +74,23 @@ done < "$SYSTEMD_CHECK_LIST_FILE" function checkService() { local SERVICE=$1; local MESSAGE="$SERVICE is not running for user $SYSTEMD_CHECK_USER"; - local COMMAND="systemctl is-active --quiet $SERVICE"; + local RESULT=1; if [ "$(id -u)" != "0" ]; then - local COMMAND="systemctl --user is-active --quiet $SERVICE"; + local USER_COMMAND="systemctl --user is-active --quiet $SERVICE"; + RESULT=$($USER_COMMAND); + else + local ROOT_COMMAND="systemctl is-active --quiet $SERVICE"; + local USER_COMMAND="$COMMAND && systemctl --user is-active --quiet $SERVICE"; + local RESULT_ROOT_COMMAND=$($ROOT_COMMAND); + local RESULT_USER_COMMAND=$($USER_COMMAND); + + if [ "$RESULT_ROOT_COMMAND" ] || [ "$RESULT_USER_COMMAND" ]; then + RESULT=0; + fi fi - if ! $($COMMAND); then + if ! "$RESULT"; then local SUBJECT="[systemd $SYSTEMD_CHECK_HOSTNAME for $SYSTEMD_CHECK_USER] CRITICAL $SERVICE"; echo "-> $SUBJECT: $MESSAGE";