From ef71e6999689131067a5fa285ad63af39569943d Mon Sep 17 00:00:00 2001 From: Cyberes Date: Fri, 29 Mar 2024 10:06:57 -0600 Subject: [PATCH] check_systemd_service: option to disable the enabled check --- check_systemd_service.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/check_systemd_service.sh b/check_systemd_service.sh index acb5625..da456bb 100755 --- a/check_systemd_service.sh +++ b/check_systemd_service.sh @@ -3,11 +3,13 @@ function usage { echo "Usage: -u [UNIT name] - -t Service is triggered by a timer or is a oneshot service. Is allowed to be inactive" + -t Service is triggered by a timer or is a oneshot service. Is allowed to be inactive + -d A service is allowed to not be enabled" } UNIT_NAME="" IS_TIMER=false +IS_ALLOWED_DISABLED=false # Parse command line arguments while getopts "u:t" opt; do @@ -18,6 +20,9 @@ while getopts "u:t" opt; do t ) IS_TIMER=true ;; + t ) + IS_ALLOWED_DISABLED=true + ;; \? ) echo "Invalid option: $OPTARG" 1>&2 exit 1 @@ -38,7 +43,7 @@ fi # Check if the unit is enabled enabled=$(systemctl is-enabled "$UNIT_NAME") -if [ "$enabled" != "enabled" ]; then +if [ "$enabled" != "enabled" ] && [ "$IS_ALLOWED_DISABLED" != true ]; then echo "CRITICAL - $UNIT_NAME is not enabled" exit 2 fi