Fix systemd
This commit is contained in:
parent
78d18d1b29
commit
47381a6765
1 changed files with 13 additions and 3 deletions
|
@ -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";
|
||||
|
||||
|
|
Loading…
Reference in a new issue