Switch to using netdata-updater.sh to toggle auto updates on and off when installing. (#12296)
* Switch to using netdata-updater.sh to toggle auto updates on and off on install. * Apply suggestions from code review Co-authored-by: Tina Luedtke <kickoke@users.noreply.github.com> * Make heading name less ambiguous. * Fix fallback case for unsupported updater script. * Fix invalid function name. Co-authored-by: Tina Luedtke <kickoke@users.noreply.github.com>
Austin S. Hemmelgarn committed
Mar 22, 2022 at 08:48 UTC
c77e3530886ca4c439dad7fa9533e3c032cfdfc5
5 files changed
+60
-111
netdata-installer.sh
+2
-24
@@ -226,9 +226,6 @@ USAGE: ${PROGRAM} [options]
226
--install <path> Install netdata in <path>. Ex. --install /opt will put netdata in /opt/netdata.
227
--dont-start-it Do not (re)start netdata after installation.
228
--dont-wait Run installation in non-interactive mode.
229
- --auto-update or -u Install netdata-updater in cron to automatically check for updates once per day.
230
- --auto-update-type Override the auto-update scheduling mechanism detection, currently supported types
231
- are: systemd, interval, crontab.
229
--stable-channel Use packages from GitHub release pages instead of nightly updates.
230
This results in less frequent updates.
231
--nightly-channel Use most recent nightly updates instead of GitHub releases.
@@ -301,7 +298,6 @@ HEREDOC
298
299
DONOTSTART=0
300
DONOTWAIT=0
304
-AUTOUPDATE=0
301
NETDATA_PREFIX=
302
LIBS_ARE_HERE=0
303
NETDATA_ENABLE_ML=""
@@ -319,19 +315,8 @@ while [ -n "${1}" ]; do
315
"--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
316
"--dont-start-it") DONOTSTART=1 ;;
317
"--dont-wait") DONOTWAIT=1 ;;
322
- "--auto-update" | "-u") AUTOUPDATE=1 ;;
323
- "--auto-update-type")
324
- AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
325
- case "${AUTO_UPDATE_TYPE}" in
326
- systemd|interval|crontab)
327
- shift 1
328
- ;;
329
- *)
330
- echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab"
331
- exit 1
332
- ;;
333
- esac
334
- ;;
318
+ "--auto-update" | "-u") ;;
319
+ "--auto-update-type") ;;
320
"--stable-channel") RELEASE_CHANNEL="stable" ;;
321
"--nightly-channel") RELEASE_CHANNEL="nightly" ;;
322
"--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-freeipmi)}" | sed 's/$/ --enable-plugin-freeipmi/g')" ;;
@@ -1955,13 +1940,6 @@ progress "Installing (but not enabling) the netdata updater tool"
1940
cleanup_old_netdata_updater || run_failed "Cannot cleanup old netdata updater tool."
1941
install_netdata_updater || run_failed "Cannot install netdata updater tool."
1942
1958
-progress "Check if we must enable/disable the netdata updater tool"
1959
-if [ "${AUTOUPDATE}" = "1" ]; then
1960
- enable_netdata_updater "${AUTO_UPDATE_TYPE}" || run_failed "Cannot enable netdata updater tool"
1961
-else
1962
- disable_netdata_updater || run_failed "Cannot disable netdata updater tool"
1963
-fi
1964
-
1943
# -----------------------------------------------------------------------------
1944
progress "Wrap up environment set up"
1945
packaging/installer/UPDATE.md
+15
-3
@@ -68,9 +68,21 @@ that prefix to this command to make sure it finds Netdata.
68
wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh
69
```
70
71
-> ❗ If the above command fails, you can [reinstall
72
-> Netdata](/packaging/installer/REINSTALL.md#one-line-installer-script-kickstartsh) to get the latest version. This also
73
-> preserves your [configuration](/docs/configure/nodes.md) in `netdata.conf` or other files.
71
+### Issues with older binpkg installs
72
+
73
+The above command is known not to work with binpkg type installs for stable releases with a version number of
74
+v1.33.1 or earlier, and nightly builds with a version number of v1.33.1-93 or earlier. If you have such a system,
75
+the above command will report that it found an existing install, and then issue a warning about not being able to
76
+find the updater script.
77
+
78
+On such installs, you can update Netdata using your distribution package manager.
79
+
80
+### If the kickstart script does not work
81
+
82
+If the above command fails, you can [reinstall
83
+Netdata](/packaging/installer/REINSTALL.md#one-line-installer-script-kickstartsh) to get the latest version. This
84
+also preserves your [configuration](/docs/configure/nodes.md) in `netdata.conf` or other files just like updating
85
+normally would, though you will need to specify any installation options you used originally again.
86
87
## Docker
88
packaging/installer/functions.sh
-70
@@ -969,76 +969,6 @@ cleanup_old_netdata_updater() {
969
return 0
970
}
971
972
-enable_netdata_updater() {
973
-
974
- if [ -n "${1}" ] ; then
975
- updater_type="${1}"
976
- else
977
- updater_type="$(_get_scheduler_type)"
978
- fi
979
-
980
- case "${updater_type}" in
981
- "systemd")
982
- systemctl enable netdata-updater.timer
983
-
984
- echo >&2 "Auto-updating has been enabled using a systemd timer unit."
985
- echo >&2
986
- echo >&2 "If the update process fails, the failure will be logged to the systemd journal just like a regular service failure."
987
- echo >&2 "Successful updates should produce empty logs."
988
- echo >&2
989
- ;;
990
- "interval")
991
- ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "$(_get_intervaldir)/netdata-updater"
992
-
993
- echo >&2 "Auto-updating has been enabled through cron, updater script linked to ${TPUT_RED}${TPUT_BOLD}$(_get_intervaldir)/netdata-updater${TPUT_RESET}"
994
- echo >&2
995
- echo >&2 "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure."
996
- echo >&2 "Successful updates will not send an email."
997
- echo >&2
998
- ;;
999
- "crontab")
1000
- cat "${NETDATA_SOURCE_DIR}/system/netdata.crontab" > "/etc/cron.d/netdata-updater"
1001
-
1002
- echo >&2 "Auto-updating has been enabled through cron, using a crontab at ${TPUT_RED}${TPUT_BOLD}/etc/cron.d/netdata-updater${TPUT_RESET}"
1003
- echo >&2
1004
- echo >&2 "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure."
1005
- echo >&2 "Successful updates will not send an email."
1006
- echo >&2
1007
- ;;
1008
- *)
1009
- echo >&2 "Unable to determine what type of auto-update scheduling to use, not enabling auto-updates."
1010
- echo >&2
1011
- return 1
1012
- esac
1013
-
1014
- return 0
1015
-}
1016
-
1017
-disable_netdata_updater() {
1018
- echo >&2 "You chose *NOT* to enable auto-update, removing any links to the updater from cron (it may have happened if you are reinstalling)"
1019
- echo >&2
1020
-
1021
- if issystemd && [ -n "$(get_systemd_service_dir)" ] ; then
1022
- systemctl disable netdata-updater.timer
1023
- fi
1024
-
1025
- if [ -d /etc/cron.daily ]; then
1026
- rm -f /etc/cron.daily/netdata-updater.sh
1027
- rm -f /etc/cron.daily/netdata-updater
1028
- fi
1029
-
1030
- if [ -d /etc/periodic/daily ]; then
1031
- rm -f /etc/periodic/daily/netdata-updater.sh
1032
- rm -f /etc/periodic/daily/netdata-updater
1033
- fi
1034
-
1035
- if [ -d /etc/cron.d ]; then
1036
- rm -f /etc/cron.d/netdata-updater
1037
- fi
1038
-
1039
- return 0
1040
-}
1041
-
972
set_netdata_updater_channel() {
973
sed -i -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" "${NETDATA_USER_CONFIG_DIR}/.environment"
974
}
packaging/installer/kickstart.sh
+42
-2
@@ -66,8 +66,9 @@ USAGE: kickstart.sh [options]
66
--dry-run Report what we would do with the given options on this system, but don’t actually do anything.
67
--stable-channel Install a stable version instead of a nightly build (default: install a nightly build)
68
--nightly-channel Install a nightly build instead of a stable version
69
- --no-updates Do not enable automatic updates (default: enable automatic updates)
69
+ --no-updates Do not enable automatic updates (default: enable automatic updates using the best supported scheduling method)
70
--auto-update Enable automatic updates.
71
+ --auto-update-type Specify a particular scheduling type for auto-updates (valid types: systemd, interval, crontab)
72
--disable-telemetry Opt-out of anonymous statistics.
73
--native-only Only install if native binary packages are available.
74
--static-only Only install if a static build is available.
@@ -699,7 +700,7 @@ handle_existing_install() {
700
701
ret=0
702
702
- if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then
703
+ if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ]; then
704
if ! update; then
705
warning "Unable to find usable updater script, not updating existing install at ${ndprefix}."
706
fi
@@ -919,6 +920,30 @@ claim() {
920
fi
921
}
922
923
+# ======================================================================
924
+# Auto-update handling code.
925
+set_auto_updates() {
926
+ if [ -x "${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh" ]; then
927
+ updater="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh"
928
+ elif [ -x "${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh" ]; then
929
+ updater="${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh"
930
+ else
931
+ warning "Could not find netdata-updater.sh. This means that auto-updates cannot (currently) be enabled on this system. See https://learn.netdata.cloud/docs/agent/packaging/installer/update for more information about updating Netdata."
932
+ return 0
933
+ fi
934
+
935
+ if [ "${NETDATA_AUTO_UPDATES}" = "1" ]; then
936
+ # This first case is for catching using a new kickstart script with an old build. It can be safely removed after v1.34.0 is released.
937
+ if ! grep -q '\-\-enable-auto-updates' ${updater}; then
938
+ echo
939
+ elif ! ${updater} --enable-auto-updates "${NETDATA_AUTO_UPDATE_TYPE}"; then
940
+ warning "Failed to enable auto updates. Netdata will still work, but you will need to update manually."
941
+ fi
942
+ else
943
+ ${updater} --disable-auto-updates
944
+ fi
945
+}
946
+
947
# ======================================================================
948
# Native package install code.
949
@@ -1400,6 +1425,7 @@ install_on_linux() {
1425
case "$?" in
1426
0)
1427
NETDATA_INSTALL_SUCCESSFUL=1
1428
+ INSTALL_PREFIX="/"
1429
;;
1430
1)
1431
fatal "Unable to install on this system." F0300
@@ -1515,6 +1541,18 @@ while [ -n "${1}" ]; do
1541
"--stable-channel") RELEASE_CHANNEL="stable" ;;
1542
"--no-updates") NETDATA_AUTO_UPDATES=0 ;;
1543
"--auto-update") NETDATA_AUTO_UPDATES="1" ;;
1544
+ "--auto-update-method")
1545
+ NETDATA_AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
1546
+ case "${NETDATA_AUTO_UPDATE_TYPE}" in
1547
+ systemd|interval|crontab)
1548
+ shift 1
1549
+ ;;
1550
+ *)
1551
+ echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab"
1552
+ exit 1
1553
+ ;;
1554
+ esac
1555
+ ;;
1556
"--reinstall") NETDATA_REINSTALL=1 ;;
1557
"--reinstall-even-if-unsafe") NETDATA_UNSAFE_REINSTALL=1 ;;
1558
"--claim-only") NETDATA_CLAIM_ONLY=1 ;;
@@ -1624,6 +1662,8 @@ elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then
1662
soft_disable_cloud
1663
fi
1664
1665
+set_auto_updates
1666
+
1667
telemetry_event INSTALL_SUCCESS "" ""
1668
cleanup
1669
trap - EXIT
packaging/makeself/install-or-update.sh
+1
-12
@@ -26,7 +26,6 @@ if [ -d /opt/netdata/etc/netdata.old ]; then
26
fi
27
28
STARTIT=1
29
-AUTOUPDATE=0
29
REINSTALL_OPTIONS=""
30
RELEASE_CHANNEL="nightly" # check .travis/create_artifacts.sh before modifying
31
@@ -36,10 +35,7 @@ while [ "${1}" ]; do
35
STARTIT=0
36
REINSTALL_OPTIONS="${REINSTALL_OPTIONS} ${1}"
37
;;
39
- "--auto-update" | "-u")
40
- AUTOUPDATE=1
41
- REINSTALL_OPTIONS="${REINSTALL_OPTIONS} ${1}"
42
- ;;
38
+ "--auto-update" | "-u") ;;
39
"--stable-channel")
40
RELEASE_CHANNEL="stable"
41
REINSTALL_OPTIONS="${REINSTALL_OPTIONS} ${1}"
@@ -161,13 +157,6 @@ progress "Install (but not enable) netdata updater tool"
157
cleanup_old_netdata_updater || run_failed "Cannot cleanup old netdata updater tool."
158
install_netdata_updater || run_failed "Cannot install netdata updater tool."
159
164
-progress "Check if we must enable/disable the netdata updater tool"
165
-if [ "${AUTOUPDATE}" = "1" ]; then
166
- enable_netdata_updater || run_failed "Cannot enable netdata updater tool"
167
-else
168
- disable_netdata_updater || run_failed "Cannot disable netdata updater tool"
169
-fi
170
-
160
# -----------------------------------------------------------------------------
161
progress "creating quick links"
162