check_systemd_service: option to disable the enabled check
This commit is contained in:
parent
5bf4de4971
commit
ef71e69996
|
@ -3,11 +3,13 @@
|
||||||
function usage {
|
function usage {
|
||||||
echo "Usage:
|
echo "Usage:
|
||||||
-u [UNIT name]
|
-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=""
|
UNIT_NAME=""
|
||||||
IS_TIMER=false
|
IS_TIMER=false
|
||||||
|
IS_ALLOWED_DISABLED=false
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
while getopts "u:t" opt; do
|
while getopts "u:t" opt; do
|
||||||
|
@ -18,6 +20,9 @@ while getopts "u:t" opt; do
|
||||||
t )
|
t )
|
||||||
IS_TIMER=true
|
IS_TIMER=true
|
||||||
;;
|
;;
|
||||||
|
t )
|
||||||
|
IS_ALLOWED_DISABLED=true
|
||||||
|
;;
|
||||||
\? )
|
\? )
|
||||||
echo "Invalid option: $OPTARG" 1>&2
|
echo "Invalid option: $OPTARG" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -38,7 +43,7 @@ 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" ]; then
|
if [ "$enabled" != "enabled" ] && [ "$IS_ALLOWED_DISABLED" != true ]; then
|
||||||
echo "CRITICAL - $UNIT_NAME is not enabled"
|
echo "CRITICAL - $UNIT_NAME is not enabled"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue