diff --git a/packaging/common/script-templates/deb-script-common.sh b/packaging/common/script-templates/deb-script-common.sh index dac4d5270..d652f2712 100644 --- a/packaging/common/script-templates/deb-script-common.sh +++ b/packaging/common/script-templates/deb-script-common.sh @@ -19,8 +19,8 @@ rc_d_path() platform_service() { - if [ -x /bin/systemctl ]; then - /bin/systemctl "$2" "$1".service + if command -v systemctl 2>/dev/null && systemctl is-system-running; then + systemctl "$2" "$1".service else /etc/init.d/"$1" "$2" fi diff --git a/packaging/common/script-templates/rpm-script-common.sh b/packaging/common/script-templates/rpm-script-common.sh index 0fdd5ef8b..4ecc5beb4 100644 --- a/packaging/common/script-templates/rpm-script-common.sh +++ b/packaging/common/script-templates/rpm-script-common.sh @@ -27,8 +27,8 @@ rc_d_path() platform_service() { - if [ -x /bin/systemctl ]; then - /bin/systemctl "$2" "$1".service + if command -v systemctl 2>/dev/null && systemctl is-system-running; then + systemctl "$2" "$1".service else `rc_d_path`/init.d/"$1" "$2" fi diff --git a/packaging/common/script-templates/script-common.sh b/packaging/common/script-templates/script-common.sh index 3c9037c4b..12ad5703a 100644 --- a/packaging/common/script-templates/script-common.sh +++ b/packaging/common/script-templates/script-common.sh @@ -29,7 +29,7 @@ case "$PKG_TYPE" in esac get_cfengine_state() { - if type systemctl >/dev/null 2>&1; then + if command -v systemctl 2>/dev/null && systemctl is-system-running; then systemctl list-units -l | sed -r -e '/^\s*(cf-[-a-z]+|cfengine3)\.service/!d' -e 's/\s*(cf-[-a-z]+|cfengine3)\.service.*/\1/' else platform_service cfengine3 status | awk '/is running/ { print $1 }' @@ -39,7 +39,7 @@ get_cfengine_state() { restore_cfengine_state() { # $1 -- file where the state to restore is saved (see get_cfengine_state()) - if type systemctl >/dev/null 2>&1; then + if command -v systemctl 2>/dev/null && systemctl is-system-running; then for service in `cat "$1"`; do definition=`systemctl cat "$service"` || continue # only try to start service that are defined/exist (some may be gone