From 1e2062fc6a6dc71eb81407016c42be4c288304bb Mon Sep 17 00:00:00 2001 From: Cyberes Date: Thu, 18 Jul 2024 19:35:26 -0600 Subject: [PATCH] check_systemd_service: make sure the service exists --- check_systemd_service.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/check_systemd_service.sh b/check_systemd_service.sh index ab69f90..28a35fc 100755 --- a/check_systemd_service.sh +++ b/check_systemd_service.sh @@ -41,6 +41,12 @@ if [ -z "$UNIT_NAME" ]; then exit -1 fi +# Check if the unit exists +if ! systemctl list-units --full -all | grep -Fq "\b$UNIT_NAME.service\b"; then + echo "CRITICAL - $UNIT_NAME does not exist" + exit 2 +fi + # Check if the unit is enabled enabled=$(systemctl is-enabled "$UNIT_NAME") if [ "$enabled" != "enabled" ] && [ "$IS_ALLOWED_DISABLED" = false ]; then