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