Fix systemd

This commit is contained in:
Alexander Schäferdiek 2019-01-25 19:43:00 +01:00
parent 78d18d1b29
commit 47381a6765

View file

@ -74,13 +74,23 @@ done < "$SYSTEMD_CHECK_LIST_FILE"
function checkService() { function checkService() {
local SERVICE=$1; local SERVICE=$1;
local MESSAGE="$SERVICE is not running for user $SYSTEMD_CHECK_USER"; 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 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 fi
if ! $($COMMAND); then if ! "$RESULT"; then
local SUBJECT="[systemd $SYSTEMD_CHECK_HOSTNAME for $SYSTEMD_CHECK_USER] CRITICAL $SERVICE"; local SUBJECT="[systemd $SYSTEMD_CHECK_HOSTNAME for $SYSTEMD_CHECK_USER] CRITICAL $SERVICE";
echo "-> $SUBJECT: $MESSAGE"; echo "-> $SUBJECT: $MESSAGE";