@cryptotaxi247 / netdata-1 / commits / 9a7bfb983

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.

Austin S. Hemmelgarn committed Jun 10, 2024 at 06:52 UTC 9a7bfb9839e49137e63e181bbd86475ed64570d5
1 file changed +32
packaging/installer/netdata-updater.sh
+32
@@ -149,6 +149,32 @@ issystemd() {
149 return 1
150 }
151
152 +# shellcheck disable=SC2009
153 +running_under_anacron() {
154 + if [ "$(uname -s)" = "Linux" ] && [ -r "/proc/$$/stat" ]; then
155 + ppid="$(cut -f 4 -d ' ' "/proc/$$/stat")"
156 + if [ -n "${ppid}" ] && [ -r "/proc/${ppid}/comm" ]; then
157 + grep -q anacron "/proc/${ppid}/comm" && return 0
158 +
159 + ppid2="$(cut -f 4 -d ' ' "/proc/${ppid}/stat")"
160 +
161 + if [ -n "${ppid2}" ] && [ -r "/proc/${ppid2}/comm" ]; then
162 + grep -q anacron "/proc/${ppid2}/comm" 2>/dev/null && return 0
163 + fi
164 + fi
165 + else
166 + ppid="$(ps -o pid= -o ppid= 2>/dev/null | grep -e "^ *$$" | xargs | cut -f 2 -d ' ')"
167 + if [ -n "${ppid}" ]; then
168 + ps -o pid= -o command= 2>/dev/null | grep -e "^ *${ppid}" | grep -q anacron && return 0
169 +
170 + ppid2="$(ps -o pid= -o ppid= 2>/dev/null | grep -e "^ *${ppid}" | xargs | cut -f 2 -d ' ')"
171 + ps -o pid= -o command= 2>/dev/null | grep -e "^ *${ppid2}" | grep -q anacron && return 0
172 + fi
173 + fi
174 +
175 + return 1
176 +}
177 +
178 _get_intervaldir() {
179 if [ -d /etc/cron.daily ]; then
180 echo /etc/cron.daily
@@ -1081,6 +1107,12 @@ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1107 NETDATA_FORCE_UPDATE=1
1108 fi
1109
1110 +# If we seem to be running under anacron, act as if we’re not running from cron.
1111 +# This is mostly to disable jitter, which should not be needed when run from anacron.
1112 +if running_under_anacron; then
1113 + NETDATA_NOT_RUNNING_FROM_CRON="${NETDATA_NOT_RUNNING_FROM_CRON:-1}"
1114 +fi
1115 +
1116 # Random sleep to alleviate stampede effect of Agents upgrading
1117 # and disconnecting/reconnecting at the same time (or near to).
1118 # But only we're not a controlling terminal (tty)