Browse Source

Add configuration file for netdata-updater.sh. (#15149)

* Add config file for netdata-updater script.

Currently only has an option to control maximal delay when adding random
jitter while updating.

Longer-term, this will be used to support a number of other
configuration options without requiring the user to handle special
arguments for the script.

* Better handle jitter config option.

* Fix DEB package builds.

* Properly mark updater config as conffile in RPM spec file.

* Switch to a proper config file in the repo.

* Add documentation about the new config file.
Austin S. Hemmelgarn 1 year ago
parent
commit
9e58153a5a

+ 1 - 0
contrib/debian/conffiles

@@ -2,3 +2,4 @@
 /etc/init.d/netdata
 /etc/logrotate.d/netdata
 /etc/netdata/netdata.conf
+/etc/netdata/netdata-updater.conf

+ 1 - 0
netdata.spec.in

@@ -495,6 +495,7 @@ rm -rf "${RPM_BUILD_ROOT}"
 %files
 %doc README.md
 %config(noreplace) %{_sysconfdir}/%{name}/netdata.conf
+%config(noreplace) %{_sysconfdir}/%{name}/netdata-updater.conf
 %attr(0755,root,netdata) %{_sysconfdir}/%{name}/edit-config
 %attr(0644,root,netdata) %{_sysconfdir}/%{name}/.install-type
 %dir %{_sysconfdir}/%{name}/health.d

+ 16 - 0
packaging/installer/UPDATE.md

@@ -166,3 +166,19 @@ and:
 ```bash
 /opt/netdata/usr/libexec/netdata/netdata-updater.sh --disable-auto-updates
 ```
+
+## Control runtime behavior of the updater script.
+
+Starting with v1.40.0, the `netdata-updater.sh` script supports a config file called `netdata-updater.conf`,
+located in the same directory as the main `netdata.conf` file. This file uses POSIX shell script syntax to define
+variables that are used by the updater.
+
+This configuration file can be edited [using our `edit-config`
+script](https://github.com/netdata/netdata/blob/master/docs/configure/nodes.md).
+
+The following configuration options are currently supported:
+
+- `NETDATA_UPDATER_JITTER`: Sets an upper limit in seconds on the random delay in the updater script when running
+  as a scheduled task. This random delay helps avoid issues resulting from too many nodes trying to reconnect to
+  the Cloud at the same time. The default value is 3600, which corresponds to one hour. Most users should not ever
+  need to change this.

+ 33 - 14
packaging/installer/netdata-updater.sh

@@ -37,6 +37,8 @@ PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packag
 NETDATA_STABLE_BASE_URL="${NETDATA_BASE_URL:-https://github.com/netdata/netdata/releases}"
 NETDATA_NIGHTLY_BASE_URL="${NETDATA_BASE_URL:-https://github.com/netdata/netdata-nightlies/releases}"
 
+NETDATA_UPDATER_JITTER=3600
+
 script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
 
 if [ -x "${script_dir}/netdata-updater" ]; then
@@ -103,6 +105,14 @@ exit_reason() {
   fi
 }
 
+is_integer () {
+  case "${1#[+-]}" in
+    *[!0123456789]*) return 1 ;;
+    '')              return 1 ;;
+    *)               return 0 ;;
+  esac
+}
+
 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
@@ -859,6 +869,11 @@ if [ -r "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
   . "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || fatal "Failed to source $(dirname "${ENVIRONMENT_FILE}")/.install-type" U0015
 fi
 
+if [ -r "$(dirname "${ENVIRONMENT_FILE}")/netdata-updater.conf" ]; then
+  # shellcheck source=/dev/null
+  . "$(dirname "${ENVIRONMENT_FILE}")/netdata-updater.conf"
+fi
+
 while [ -n "${1}" ]; do
   case "${1}" in
     --not-running-from-cron) NETDATA_NOT_RUNNING_FROM_CRON=1 ;;
@@ -867,17 +882,17 @@ while [ -n "${1}" ]; do
     --non-interactive) INTERACTIVE=0 ;;
     --interactive) INTERACTIVE=1 ;;
     --tmpdir-path)
-        NETDATA_TMPDIR_PATH="${2}"
-        shift 1
-        ;;
+      NETDATA_TMPDIR_PATH="${2}"
+      shift 1
+      ;;
     --enable-auto-updates)
-        enable_netdata_updater "${2}"
-        exit $?
-        ;;
+      enable_netdata_updater "${2}"
+      exit $?
+      ;;
     --disable-auto-updates)
-        disable_netdata_updater
-        exit $?
-        ;;
+      disable_netdata_updater
+      exit $?
+      ;;
     *) fatal "Unrecognized option ${1}" U001A ;;
   esac
 
@@ -888,12 +903,16 @@ done
 # and disconnecting/reconnecting at the same time (or near to).
 # But only we're not a controlling terminal (tty)
 # Randomly sleep between 1s and 60m
-if [ ! -t 1 ] && [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ]; then
-    rnd="$(awk '
+if [ ! -t 1 ] && \
+   [ -z "${GITHUB_ACTIONS}" ] && \
+   [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ] && \
+   is_integer "${NETDATA_UPDATER_JITTER}" && \
+   [ "${NETDATA_UPDATER_JITTER}" -gt 1 ]; then
+    rnd="$(awk "
       BEGIN { srand()
-              printf("%d\n", 3600 * rand())
-      }')"
-    sleep $(((rnd % 3600) + 1))
+              printf(\"%d\\n\", ${NETDATA_UPDATER_JITTER} * rand())
+      }")"
+    sleep $(((rnd % NETDATA_UPDATER_JITTER) + 1))
 fi
 
 # We dont expect to find lib dir variable on older installations, so load this path if none found

+ 1 - 0
system/Makefile.am

@@ -26,6 +26,7 @@ dist_config_SCRIPTS = \
 
 dist_config_DATA = \
     .install-type \
+    netdata-updater.conf \
     $(NULL)
 
 libconfigvnodesdir=$(libconfigdir)/vnodes

+ 7 - 0
system/netdata-updater.conf

@@ -0,0 +1,7 @@
+# Configuration for netdata-updater.sh script.
+#
+# When run non-interactively, the updater script will delay some
+# random number of seconds up to NETDATA_UPDATER_JITTER before
+# actually running the update. The default is 3600 (one
+# hour). Most users should not need to change this.
+#NETDATA_UPDATER_JITTER="3600"