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 committed
Jun 29, 2023 at 08:58 UTC
9e58153a5a0577970ca185b8d65f031703001157
6 files changed
+59
-14
contrib/debian/conffiles
+1
@@ -2,3 +2,4 @@
2
/etc/init.d/netdata
3
/etc/logrotate.d/netdata
4
/etc/netdata/netdata.conf
5
+/etc/netdata/netdata-updater.conf
netdata.spec.in
+1
@@ -495,6 +495,7 @@ rm -rf "${RPM_BUILD_ROOT}"
495
%files
496
%doc README.md
497
%config(noreplace) %{_sysconfdir}/%{name}/netdata.conf
498
+%config(noreplace) %{_sysconfdir}/%{name}/netdata-updater.conf
499
%attr(0755,root,netdata) %{_sysconfdir}/%{name}/edit-config
500
%attr(0644,root,netdata) %{_sysconfdir}/%{name}/.install-type
501
%dir %{_sysconfdir}/%{name}/health.d
packaging/installer/UPDATE.md
+16
@@ -166,3 +166,19 @@ and:
166
```bash
167
/opt/netdata/usr/libexec/netdata/netdata-updater.sh --disable-auto-updates
168
```
169
+
170
+## Control runtime behavior of the updater script.
171
+
172
+Starting with v1.40.0, the `netdata-updater.sh` script supports a config file called `netdata-updater.conf`,
173
+located in the same directory as the main `netdata.conf` file. This file uses POSIX shell script syntax to define
174
+variables that are used by the updater.
175
+
176
+This configuration file can be edited [using our `edit-config`
177
+script](https://github.com/netdata/netdata/blob/master/docs/configure/nodes.md).
178
+
179
+The following configuration options are currently supported:
180
+
181
+- `NETDATA_UPDATER_JITTER`: Sets an upper limit in seconds on the random delay in the updater script when running
182
+ as a scheduled task. This random delay helps avoid issues resulting from too many nodes trying to reconnect to
183
+ the Cloud at the same time. The default value is 3600, which corresponds to one hour. Most users should not ever
184
+ need to change this.
packaging/installer/netdata-updater.sh
+33
-14
@@ -37,6 +37,8 @@ PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packag
37
NETDATA_STABLE_BASE_URL="${NETDATA_BASE_URL:-https://github.com/netdata/netdata/releases}"
38
NETDATA_NIGHTLY_BASE_URL="${NETDATA_BASE_URL:-https://github.com/netdata/netdata-nightlies/releases}"
39
40
+NETDATA_UPDATER_JITTER=3600
41
+
42
script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
43
44
if [ -x "${script_dir}/netdata-updater" ]; then
@@ -103,6 +105,14 @@ exit_reason() {
105
fi
106
}
107
108
+is_integer () {
109
+ case "${1#[+-]}" in
110
+ *[!0123456789]*) return 1 ;;
111
+ '') return 1 ;;
112
+ *) return 0 ;;
113
+ esac
114
+}
115
+
116
issystemd() {
117
# if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
118
if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then
@@ -859,6 +869,11 @@ if [ -r "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
869
. "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || fatal "Failed to source $(dirname "${ENVIRONMENT_FILE}")/.install-type" U0015
870
fi
871
872
+if [ -r "$(dirname "${ENVIRONMENT_FILE}")/netdata-updater.conf" ]; then
873
+ # shellcheck source=/dev/null
874
+ . "$(dirname "${ENVIRONMENT_FILE}")/netdata-updater.conf"
875
+fi
876
+
877
while [ -n "${1}" ]; do
878
case "${1}" in
879
--not-running-from-cron) NETDATA_NOT_RUNNING_FROM_CRON=1 ;;
@@ -867,17 +882,17 @@ while [ -n "${1}" ]; do
882
--non-interactive) INTERACTIVE=0 ;;
883
--interactive) INTERACTIVE=1 ;;
884
--tmpdir-path)
870
- NETDATA_TMPDIR_PATH="${2}"
871
- shift 1
872
- ;;
885
+ NETDATA_TMPDIR_PATH="${2}"
886
+ shift 1
887
+ ;;
888
--enable-auto-updates)
874
- enable_netdata_updater "${2}"
875
- exit $?
876
- ;;
889
+ enable_netdata_updater "${2}"
890
+ exit $?
891
+ ;;
892
--disable-auto-updates)
878
- disable_netdata_updater
879
- exit $?
880
- ;;
893
+ disable_netdata_updater
894
+ exit $?
895
+ ;;
896
*) fatal "Unrecognized option ${1}" U001A ;;
897
esac
898
@@ -888,12 +903,16 @@ done
903
# and disconnecting/reconnecting at the same time (or near to).
904
# But only we're not a controlling terminal (tty)
905
# Randomly sleep between 1s and 60m
891
-if [ ! -t 1 ] && [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ]; then
892
- rnd="$(awk '
906
+if [ ! -t 1 ] && \
907
+ [ -z "${GITHUB_ACTIONS}" ] && \
908
+ [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ] && \
909
+ is_integer "${NETDATA_UPDATER_JITTER}" && \
910
+ [ "${NETDATA_UPDATER_JITTER}" -gt 1 ]; then
911
+ rnd="$(awk "
912
BEGIN { srand()
894
- printf("%d\n", 3600 * rand())
895
- }')"
896
- sleep $(((rnd % 3600) + 1))
913
+ printf(\"%d\\n\", ${NETDATA_UPDATER_JITTER} * rand())
914
+ }")"
915
+ sleep $(((rnd % NETDATA_UPDATER_JITTER) + 1))
916
fi
917
918
# We dont expect to find lib dir variable on older installations, so load this path if none found
system/Makefile.am
+1
@@ -26,6 +26,7 @@ dist_config_SCRIPTS = \
26
27
dist_config_DATA = \
28
.install-type \
29
+ netdata-updater.conf \
30
$(NULL)
31
32
libconfigvnodesdir=$(libconfigdir)/vnodes
system/netdata-updater.conf
new
+7
@@ -0,0 +1,7 @@
1
+# Configuration for netdata-updater.sh script.
2
+#
3
+# When run non-interactively, the updater script will delay some
4
+# random number of seconds up to NETDATA_UPDATER_JITTER before
5
+# actually running the update. The default is 3600 (one
6
+# hour). Most users should not need to change this.
7
+#NETDATA_UPDATER_JITTER="3600"