mirror of
https://github.com/netdata/netdata.git
synced 2025-04-06 22:38:55 +00:00
Assorted systemd detection fixes (#19345)
Assorted systemd detection fixes: - Properly scope `set -e` changes to only affect `systemctl is-system-running` invocation. - Skip checking for hard-coded unit file paths. Other paths may technically be used for unit files instead of what we hard-code, and the presence or abscence of any specific unit file path _does not_ reliably indicate the presence or abscence of systemd.
This commit is contained in:
parent
c83d33b2ae
commit
40ab14d0d5
4 changed files with 13 additions and 32 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue