check_systemd_service: make sure the service exists

This commit is contained in:
Cyberes 2024-07-18 19:35:26 -06:00
parent 36fb1e26c4
commit 1e2062fc6a
1 changed files with 6 additions and 0 deletions

View File

@ -41,6 +41,12 @@ if [ -z "$UNIT_NAME" ]; then
exit -1 exit -1
fi 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 # Check if the unit is enabled
enabled=$(systemctl is-enabled "$UNIT_NAME") enabled=$(systemctl is-enabled "$UNIT_NAME")
if [ "$enabled" != "enabled" ] && [ "$IS_ALLOWED_DISABLED" = false ]; then if [ "$enabled" != "enabled" ] && [ "$IS_ALLOWED_DISABLED" = false ]; then