diff --git a/usr/local/bin/systemd_check b/usr/local/bin/systemd_check index 134aa1b..a3953ce 100755 --- a/usr/local/bin/systemd_check +++ b/usr/local/bin/systemd_check @@ -74,21 +74,18 @@ done < "$SYSTEMD_CHECK_LIST_FILE" function checkService() { local SERVICE=$1; local MESSAGE="$SERVICE is not running for user $SYSTEMD_CHECK_USER"; + + local ROOT_COMMAND="systemctl is-active --quiet $SERVICE"; + local USER_COMMAND="systemctl --user is-active --quiet $SERVICE"; + local RESULT=1; if [ "$(id -u)" != "0" ]; then - local USER_COMMAND="systemctl --user is-active --quiet $SERVICE"; - RESULT=$($USER_COMMAND); - if [ -z "$RESULT" ]; then + if [ $($USER_COMMAND) ]; then RESULT=0; fi else - local ROOT_COMMAND="systemctl is-active --quiet $SERVICE"; - local USER_COMMAND="systemctl --user is-active --quiet $SERVICE"; - local RESULT_ROOT_COMMAND=$($ROOT_COMMAND); - local RESULT_USER_COMMAND=$($USER_COMMAND); - - if [ -z "$RESULT_ROOT_COMMAND" ] || [ -z "$RESULT_USER_COMMAND" ]; then + if [ $($ROOT_COMMAND) ] || [ $($USER_COMMAND) ]; then RESULT=0; fi fi