summaryrefslogtreecommitdiffstats
path: root/packaging
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2024-06-10 06:52:59 -0400
committerGitHub <noreply@github.com>2024-06-10 06:52:59 -0400
commit9a7bfb9839e49137e63e181bbd86475ed64570d5 (patch)
treea37c0429b38a8ca8337c52d1518bc513907820f8 /packaging
parentf121466f29e5ed40d6157440f0ca535f2d92abc5 (diff)
Disable updater jitter when run from anacron. (#17826)
* Disable updater jitter when run from anacron. * Adjust checking to account for busybox ps. * Check process grandparents as well to handle the use of run-parts. * Make anacron check more portable. On Linux when procfs is mounted, use that instead of `ps` because some older Linux systems apparently don’t support the `ppid` field in `ps`. Also, allow a variable number of spaces prior to the PID when parsing `ps` output, as this is less portable than I first realized. * Address a few additional issues in the detection code. * Fix additional regexes when parsing ps output.
Diffstat (limited to 'packaging')
-rwxr-xr-xpackaging/installer/netdata-updater.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh
index 4fb45bce5d..2fdc0e2709 100755
--- a/packaging/installer/netdata-updater.sh
+++ b/packaging/installer/netdata-updater.sh
@@ -149,6 +149,32 @@ issystemd() {
return 1
}
+# shellcheck disable=SC2009
+running_under_anacron() {
+ if [ "$(uname -s)" = "Linux" ] && [ -r "/proc/$$/stat" ]; then
+ ppid="$(cut -f 4 -d ' ' "/proc/$$/stat")"
+ if [ -n "${ppid}" ] && [ -r "/proc/${ppid}/comm" ]; then
+ grep -q anacron "/proc/${ppid}/comm" && return 0
+
+ ppid2="$(cut -f 4 -d ' ' "/proc/${ppid}/stat")"
+
+ if [ -n "${ppid2}" ] && [ -r "/proc/${ppid2}/comm" ]; then
+ grep -q anacron "/proc/${ppid2}/comm" 2>/dev/null && return 0
+ fi
+ fi
+ else
+ ppid="$(ps -o pid= -o ppid= 2>/dev/null | grep -e "^ *$$" | xargs | cut -f 2 -d ' ')"
+ if [ -n "${ppid}" ]; then
+ ps -o pid= -o command= 2>/dev/null | grep -e "^ *${ppid}" | grep -q anacron && return 0
+
+ ppid2="$(ps -o pid= -o ppid= 2>/dev/null | grep -e "^ *${ppid}" | xargs | cut -f 2 -d ' ')"
+ ps -o pid= -o command= 2>/dev/null | grep -e "^ *${ppid2}" | grep -q anacron && return 0
+ fi
+ fi
+
+ return 1
+}
+
_get_intervaldir() {
if [ -d /etc/cron.daily ]; then
echo /etc/cron.daily
@@ -1081,6 +1107,12 @@ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
NETDATA_FORCE_UPDATE=1
fi
+# If we seem to be running under anacron, act as if we’re not running from cron.
+# This is mostly to disable jitter, which should not be needed when run from anacron.
+if running_under_anacron; then
+ NETDATA_NOT_RUNNING_FROM_CRON="${NETDATA_NOT_RUNNING_FROM_CRON:-1}"
+fi
+
# Random sleep to alleviate stampede effect of Agents upgrading
# and disconnecting/reconnecting at the same time (or near to).
# But only we're not a controlling terminal (tty)