diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index 76a1501bab..241ba59eb5 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -608,6 +608,18 @@ issystemd() { return 1 fi + # Check the output of systemctl is-system-running. + # If this reports 'offline', it’s not systemd. If it reports 'unknown' + # or nothing at all (which indicates the command is not supported), it + # may or may not be systemd, so continue to other checks. If it reports + # anything else, it is systemd. + case "$(systemctl is-system-running)" in + offline) return 1 ;; + unknown) : ;; + "") : ;; + *) return 0 ;; + esac + # if pid 1 is systemd, it is systemd [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0 diff --git a/packaging/installer/netdata-uninstaller.sh b/packaging/installer/netdata-uninstaller.sh index 3b438ffc3e..cf68ed49a9 100755 --- a/packaging/installer/netdata-uninstaller.sh +++ b/packaging/installer/netdata-uninstaller.sh @@ -474,6 +474,18 @@ issystemd() { return 1 fi + # Check the output of systemctl is-system-running. + # If this reports 'offline', it’s not systemd. If it reports 'unknown' + # or nothing at all (which indicates the command is not supported), it + # may or may not be systemd, so continue to other checks. If it reports + # anything else, it is systemd. + case "$(systemctl is-system-running)" in + offline) return 1 ;; + unknown) : ;; + "") : ;; + *) return 0 ;; + esac + # if pid 1 is systemd, it is systemd [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0 diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index 18d58a4ab9..4b54c3f867 100755 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -111,6 +111,20 @@ is_integer () { esac } +safe_pidof() { + pidof_cmd="$(command -v pidof 2> /dev/null)" + if [ -n "${pidof_cmd}" ]; then + ${pidof_cmd} "${@}" + return $? + else + ps -acxo pid,comm | + sed "s/^ *//g" | + grep netdata | + cut -d ' ' -f 1 + return $? + fi +} + 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 @@ -123,6 +137,23 @@ issystemd() { return 1 fi + # Check the output of systemctl is-system-running. + # If this reports 'offline', it’s not systemd. If it reports 'unknown' + # or nothing at all (which indicates the command is not supported), it + # may or may not be systemd, so continue to other checks. If it reports + # 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. + set +e + case "$(systemctl is-system-running)" 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 @@ -346,6 +377,91 @@ disable_netdata_updater() { return 0 } +auto_update_status() { + case "$(_get_scheduler_type)" in + systemd) info "The default auto-update scheduling method for this system is: systemd timer units" ;; + crontab) info "The default auto-update scheduling method for this system is: drop-in crontab" ;; + interval) info "The default auto-update scheduling method for this system is: drop-in periodic script" ;; + *) info "No recognized auto-update scheduling method found" ; return ;; + esac + + duplicate="" + enabled="" + + if issystemd; then + if systemctl list-units --full -all | grep -Fq "netdata-updater.timer"; then + if systemctl is-enabled netdata-updater.timer; then + info "Auto-updates using a systemd timer unit are ENABLED" + enabled="systemd" + else + info "Auto-updates using a systemd timer unit are DISABLED" + fi + else + info "Auto-updates using a systemd timer unit are NOT SUPPORTED due to: Required unit files not installed" + fi + else + info "Auto-updates using a systemd timer unit are NOT SUPPORTED due to: Systemd not present" + fi + + interval_found="" + + if [ -d /etc/cron.daily ]; then + interval_found="1" + + if [ -x /etc/cron.daily/netdata-updater.sh ] || [ -x /etc/cron.daily/netdata-updater ]; then + info "Auto-updates using a drop-in periodic script in /etc/cron.daily are ENABLED" + + if [ -n "${enabled}" ]; then + duplicate="1" + else + enabled="cron.daily" + fi + else + info "Auto-updates using a drop-in periodic script in /etc/cron.daily are DISABLED" + fi + else + info "Auto-updates using a drop-in periodic script in /etc/cron.daily are NOT SUPPORTED: due to: Directory does not exist" + fi + + if [ -d /etc/periodic/daily ]; then + if [ -x /etc/periodic/daily/netdata-updater.sh ] || [ -x /etc/periodic/daily/netdata-updater ]; then + info "Auto-updates using a drop-in periodic script in /etc/periodic/daily are ENABLED" + + if [ -n "${enabled}" ]; then + duplicate="1" + else + enabled="periodic/daily" + fi + else + if [ -z "${interval_found}" ]; then + info "Auto-updates using a drop-in periodic script in /etc/periodic/daily are DISABLED" + fi + fi + elif [ -z "${interval_found}" ]; then + info "Auto-updates using a drop-in periodic script in /etc/periodic/daily are NOT SUPPORTED due to: Directory does not exist" + fi + + if [ -d /etc/cron.d ]; then + if [ -f /etc/cron.d/netdata-updater ] || [ -f /etc/cron.d/netdata-updater-daily ]; then + info "Auto-updates using a drop-in crontab are ENABLED" + + if [ -n "${enabled}" ]; then + duplicate="1" + else + enabled="cron.d" + fi + else + info "Auto-updates using a drop-in crontab are DISABLED" + fi + else + info "Auto-updates using a drop-in crontab are NOT SUPPORTED due to: Directory does not exist" + fi + + if [ -n "${duplicate}" ]; then + warning "More than one method of auto-updates is enabled! Please disable and re-enable auto-updates to correct this." + fi +} + str_in_list() { printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$" return $? @@ -1123,6 +1239,10 @@ while [ -n "${1}" ]; do disable_netdata_updater exit $? ;; + --auto-update-status) + auto_update_status + exit 0 + ;; *) fatal "Unrecognized option ${1}" U001A ;; esac diff --git a/system/install-service.sh.in b/system/install-service.sh.in index 0ed4fa1bb7..43a607ce92 100755 --- a/system/install-service.sh.in +++ b/system/install-service.sh.in @@ -193,6 +193,19 @@ _check_systemd() { # if there is no systemctl command, it is not systemd [ -z "$(command -v systemctl 2>/dev/null || true)" ] && echo "NO" && return 0 + # Check the output of systemctl is-system-running. + # + # 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 + 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