mirror of
https://github.com/ovh/debian-cis.git
synced 2025-08-04 14:21:15 +02:00
refacto: systemd is-active / is-enabled
Manage different object types in a generic way. Add 'timer' ie-enabled
This commit is contained in:
75
lib/utils.sh
75
lib/utils.sh
@@ -305,9 +305,10 @@ does_group_exist() {
|
|||||||
# Service Boot Checks
|
# Service Boot Checks
|
||||||
#
|
#
|
||||||
|
|
||||||
is_service_enabled() {
|
systemd_is_active_or_enabled() {
|
||||||
local SERVICE=$1
|
local SYSTEMD_OBJECT=$1
|
||||||
|
local SYSTEMD_OBJECT_TYPE=$2
|
||||||
|
local SYSTEMD_ACTION=$3
|
||||||
# if running in a container, it does not make much sense to test for systemd / service
|
# if running in a container, it does not make much sense to test for systemd / service
|
||||||
# the var "IS_CONTAINER" defined in lib/constant may not be enough, in case we are using systemd slices
|
# the var "IS_CONTAINER" defined in lib/constant may not be enough, in case we are using systemd slices
|
||||||
# currently, did not find a unified way to manage all cases, so we check this only for systemctl usage
|
# currently, did not find a unified way to manage all cases, so we check this only for systemctl usage
|
||||||
@@ -317,13 +318,75 @@ is_service_enabled() {
|
|||||||
FNRET=1
|
FNRET=1
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if $SUDO_CMD systemctl -t service is-enabled "$SERVICE" >/dev/null; then
|
|
||||||
debug "Service $SERVICE is enabled"
|
if $SUDO_CMD systemctl -t "$SYSTEMD_OBJECT_TYPE" "$SYSTEMD_ACTION" "$SYSTEMD_OBJECT" >/dev/null; then
|
||||||
FNRET=0
|
FNRET=0
|
||||||
else
|
else
|
||||||
debug "Service $SERVICE is disabled"
|
|
||||||
FNRET=1
|
FNRET=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
is_service_enabled() {
|
||||||
|
local SERVICE=$1
|
||||||
|
|
||||||
|
systemd_is_active_or_enabled "$SERVICE" 'service' 'is-enabled'
|
||||||
|
|
||||||
|
if [ "$FNRET" -eq 0 ]; then
|
||||||
|
debug "Service $SERVICE is enabled"
|
||||||
|
else
|
||||||
|
debug "Service $SERVICE is not enabled"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
is_service_active() {
|
||||||
|
local SERVICE=$1
|
||||||
|
|
||||||
|
systemd_is_active_or_enabled "$SERVICE" 'service' 'is-active'
|
||||||
|
|
||||||
|
if [ "$FNRET" -eq 0 ]; then
|
||||||
|
debug "Service $SERVICE is active"
|
||||||
|
else
|
||||||
|
debug "Service $SERVICE is not active"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_socket_enabled() {
|
||||||
|
local SOCKET=$1
|
||||||
|
|
||||||
|
systemd_is_active_or_enabled "$SOCKET" 'socket' 'is-enabled'
|
||||||
|
|
||||||
|
if [ "$FNRET" -eq 0 ]; then
|
||||||
|
debug "Socket $SOCKET is enabled"
|
||||||
|
else
|
||||||
|
debug "Socket $SOCKET is not enabled"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
is_socket_active() {
|
||||||
|
local SOCKET=$1
|
||||||
|
|
||||||
|
systemd_is_active_or_enabled "$SOCKET" 'socket' 'is-active'
|
||||||
|
|
||||||
|
if [ "$FNRET" -eq 0 ]; then
|
||||||
|
debug "Socket $SOCKET is active"
|
||||||
|
else
|
||||||
|
debug "Socket $SOCKET is not active"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_timer_enabled() {
|
||||||
|
local TIMER=$1
|
||||||
|
|
||||||
|
systemd_is_active_or_enabled "$TIMER" 'timer' 'is-active'
|
||||||
|
|
||||||
|
if [ "$FNRET" -eq 0 ]; then
|
||||||
|
debug "Timer $TIMER is active"
|
||||||
|
else
|
||||||
|
debug "Timer $TIMER is not active"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user