diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index 241ba59eb5..d043b298ca 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -597,11 +597,6 @@ issystemd() { ns='' systemctl='' - # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd - if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then - return 1 - fi - # if there is no systemctl command, it is not systemd systemctl=$(command -v systemctl 2> /dev/null) if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then diff --git a/packaging/installer/netdata-uninstaller.sh b/packaging/installer/netdata-uninstaller.sh index cf68ed49a9..7be6fa1734 100755 --- a/packaging/installer/netdata-uninstaller.sh +++ b/packaging/installer/netdata-uninstaller.sh @@ -463,11 +463,6 @@ issystemd() { ns='' systemctl='' - # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd - if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then - return 1 - fi - # if there is no systemctl command, it is not systemd systemctl=$(command -v systemctl 2> /dev/null) if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index 4b54c3f867..cc153349f8 100755 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -126,11 +126,6 @@ safe_pidof() { } issystemd() { - # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd - if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then - return 1 - fi - # if there is no systemctl command, it is not systemd systemctl=$(command -v systemctl 2> /dev/null) if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then @@ -144,15 +139,18 @@ issystemd() { # anything else, it is systemd. # # This may return a non-zero exit status in cases when it actually - # succeeded for our purposes, so we need to toggle set -e off here. + # succeeded for our purposes (notably, if the state is `degraded`), + # so we need to toggle set -e off here. set +e - case "$(systemctl is-system-running)" in + systemd_state="$(systemctl is-system-running)" + set -e + + case "${systemd_state}" in offline) return 1 ;; unknown) : ;; "") : ;; *) return 0 ;; esac - set -e # if pid 1 is systemd, it is systemd [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0 diff --git a/system/install-service.sh.in b/system/install-service.sh.in index 43a607ce92..e81e36df7b 100755 --- a/system/install-service.sh.in +++ b/system/install-service.sh.in @@ -185,11 +185,6 @@ _check_systemd() { myns='' ns='' - # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd - if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then - echo "NO" && return 0 - fi - # if there is no systemctl command, it is not systemd [ -z "$(command -v systemctl 2>/dev/null || true)" ] && echo "NO" && return 0 @@ -198,22 +193,19 @@ _check_systemd() { # This may return a non-zero exit status in cases when it actually # succeeded for our purposes, so we need to toggle set -e off here. set +e - case "$(systemctl is-system-running)" in + systemd_state="$(systemctl is-system-running)" + set -e + + case "${systemd_state}" in offline) echo "OFFLINE" && return 0 ;; unknown) : ;; "") : ;; *) echo "YES" && return 0 ;; esac - set -e # if pid 1 is systemd, it is systemd [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && echo "YES" && return 0 - # it ‘is’ systemd at this point, but systemd might not be running - # if not, return 2 to indicate ‘systemd, but not running’ - pids=$(safe_pidof systemd 2> /dev/null) - [ -z "${pids}" ] && echo "OFFLINE" && return 0 - # check if the running systemd processes are not in our namespace myns="$(readlink /proc/self/ns/pid 2> /dev/null)" for p in ${pids}; do @@ -223,8 +215,9 @@ _check_systemd() { [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && echo "YES" && return 0 done - # else, it is not systemd - echo "NO" + # At this point, we know it’s a systemd system because systemctl + # exists, but systemd does not appear to be running, so indicate as such + echo "OFFLINE" } check_systemd() {