mirror of
https://github.com/netdata/netdata.git
synced 2025-04-23 13:00:23 +00:00
Add option to updater to report status of auto-updates on the system. (#19248)
* Add option to updater to report status of auto-updates on the system. * Improve systemd detection. The _official_ way to check if a system is running systemd is to call `systemctl is-system-running` and check the output. This adds that checking to places where we are otherwise looking for systemd. * Remove pointless subshell.
This commit is contained in:
parent
1cb0ce4980
commit
64b9f5e280
4 changed files with 157 additions and 0 deletions
|
@ -608,6 +608,18 @@ issystemd() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
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
|
# if pid 1 is systemd, it is systemd
|
||||||
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
|
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
|
||||||
|
|
||||||
|
|
|
@ -474,6 +474,18 @@ issystemd() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
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
|
# if pid 1 is systemd, it is systemd
|
||||||
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
|
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,20 @@ is_integer () {
|
||||||
esac
|
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() {
|
issystemd() {
|
||||||
# if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
|
# 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
|
if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then
|
||||||
|
@ -123,6 +137,23 @@ issystemd() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
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
|
# if pid 1 is systemd, it is systemd
|
||||||
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
|
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
|
||||||
|
|
||||||
|
@ -346,6 +377,91 @@ disable_netdata_updater() {
|
||||||
return 0
|
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() {
|
str_in_list() {
|
||||||
printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$"
|
printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$"
|
||||||
return $?
|
return $?
|
||||||
|
@ -1123,6 +1239,10 @@ while [ -n "${1}" ]; do
|
||||||
disable_netdata_updater
|
disable_netdata_updater
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
|
--auto-update-status)
|
||||||
|
auto_update_status
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
*) fatal "Unrecognized option ${1}" U001A ;;
|
*) fatal "Unrecognized option ${1}" U001A ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,19 @@ _check_systemd() {
|
||||||
# if there is no systemctl command, it is not systemd
|
# if there is no systemctl command, it is not systemd
|
||||||
[ -z "$(command -v systemctl 2>/dev/null || true)" ] && echo "NO" && return 0
|
[ -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
|
# if pid 1 is systemd, it is systemd
|
||||||
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && echo "YES" && return 0
|
[ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && echo "YES" && return 0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue