diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2023-06-29 08:58:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-29 08:58:40 -0400 |
commit | 9e58153a5a0577970ca185b8d65f031703001157 (patch) | |
tree | 4de2782365191c36ef2b518ec32f52127f67ee65 /packaging | |
parent | c62dcb2a9bd8ca6ec0c483bb3506c733d96648c6 (diff) |
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.
Diffstat (limited to 'packaging')
-rw-r--r-- | packaging/installer/UPDATE.md | 16 | ||||
-rwxr-xr-x | packaging/installer/netdata-updater.sh | 47 |
2 files changed, 49 insertions, 14 deletions
diff --git a/packaging/installer/UPDATE.md b/packaging/installer/UPDATE.md index 3df84023b8..0a425c523b 100644 --- a/packaging/installer/UPDATE.md +++ b/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. diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index f8edb6d712..1b13e5fcb7 100755 --- a/packaging/installer/netdata-updater.sh +++ b/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 |