diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2022-03-22 08:48:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 08:48:06 -0400 |
commit | c77e3530886ca4c439dad7fa9533e3c032cfdfc5 (patch) | |
tree | cf7442fd715f0cb339e9c554ad791e656ce34d6d | |
parent | 4a4817d8a4569810bf6883d1fc56f39221f19cc7 (diff) |
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>
-rwxr-xr-x | netdata-installer.sh | 26 | ||||
-rw-r--r-- | packaging/installer/UPDATE.md | 18 | ||||
-rw-r--r-- | packaging/installer/functions.sh | 70 | ||||
-rwxr-xr-x | packaging/installer/kickstart.sh | 44 | ||||
-rwxr-xr-x | packaging/makeself/install-or-update.sh | 13 |
5 files changed, 60 insertions, 111 deletions
diff --git a/netdata-installer.sh b/netdata-installer.sh index 3de15622f8..545fe61fb4 100755 --- a/netdata-installer.sh +++ b/netdata-installer.sh @@ -226,9 +226,6 @@ USAGE: ${PROGRAM} [options] --install <path> Install netdata in <path>. Ex. --install /opt will put netdata in /opt/netdata. --dont-start-it Do not (re)start netdata after installation. --dont-wait Run installation in non-interactive mode. - --auto-update or -u Install netdata-updater in cron to automatically check for updates once per day. - --auto-update-type Override the auto-update scheduling mechanism detection, currently supported types - are: systemd, interval, crontab. --stable-channel Use packages from GitHub release pages instead of nightly updates. This results in less frequent updates. --nightly-channel Use most recent nightly updates instead of GitHub releases. @@ -301,7 +298,6 @@ HEREDOC DONOTSTART=0 DONOTWAIT=0 -AUTOUPDATE=0 NETDATA_PREFIX= LIBS_ARE_HERE=0 NETDATA_ENABLE_ML="" @@ -319,19 +315,8 @@ while [ -n "${1}" ]; do "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;; "--dont-start-it") DONOTSTART=1 ;; "--dont-wait") DONOTWAIT=1 ;; - "--auto-update" | "-u") AUTOUPDATE=1 ;; - "--auto-update-type") - AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')" - case "${AUTO_UPDATE_TYPE}" in - systemd|interval|crontab) - shift 1 - ;; - *) - echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab" - exit 1 - ;; - esac - ;; + "--auto-update" | "-u") ;; + "--auto-update-type") ;; "--stable-channel") RELEASE_CHANNEL="stable" ;; "--nightly-channel") RELEASE_CHANNEL="nightly" ;; "--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" cleanup_old_netdata_updater || run_failed "Cannot cleanup old netdata updater tool." install_netdata_updater || run_failed "Cannot install netdata updater tool." -progress "Check if we must enable/disable the netdata updater tool" -if [ "${AUTOUPDATE}" = "1" ]; then - enable_netdata_updater "${AUTO_UPDATE_TYPE}" || run_failed "Cannot enable netdata updater tool" -else - disable_netdata_updater || run_failed "Cannot disable netdata updater tool" -fi - # ----------------------------------------------------------------------------- progress "Wrap up environment set up" diff --git a/packaging/installer/UPDATE.md b/packaging/installer/UPDATE.md index 60fcbfa9d2..009e970f28 100644 --- a/packaging/installer/UPDATE.md +++ b/packaging/installer/UPDATE.md @@ -68,9 +68,21 @@ that prefix to this command to make sure it finds Netdata. wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh ``` -> ❗ If the above command fails, you can [reinstall -> Netdata](/packaging/installer/REINSTALL.md#one-line-installer-script-kickstartsh) to get the latest version. This also -> preserves your [configuration](/docs/configure/nodes.md) in `netdata.conf` or other files. +### Issues with older binpkg installs + +The above command is known not to work with binpkg type installs for stable releases with a version number of +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, +the above command will report that it found an existing install, and then issue a warning about not being able to +find the updater script. + +On such installs, you can update Netdata using your distribution package manager. + +### If the kickstart script does not work + +If the above command fails, you can [reinstall +Netdata](/packaging/installer/REINSTALL.md#one-line-installer-script-kickstartsh) to get the latest version. This +also preserves your [configuration](/docs/configure/nodes.md) in `netdata.conf` or other files just like updating +normally would, though you will need to specify any installation options you used originally again. ## Docker diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index bc47d722ce..471e64571b 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -969,76 +969,6 @@ cleanup_old_netdata_updater() { return 0 } -enable_netdata_updater() { - - if [ -n "${1}" ] ; then - updater_type="${1}" - else - updater_type="$(_get_scheduler_type)" - fi - - case "${updater_type}" in - "systemd") - systemctl enable netdata-updater.timer - - echo >&2 "Auto-updating has been enabled using a systemd timer unit." - echo >&2 - echo >&2 "If the update process fails, the failure will be logged to the systemd journal just like a regular service failure." - echo >&2 "Successful updates should produce empty logs." - echo >&2 - ;; - "interval") - ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "$(_get_intervaldir)/netdata-updater" - - echo >&2 "Auto-updating has been enabled through cron, updater script linked to ${TPUT_RED}${TPUT_BOLD}$(_get_intervaldir)/netdata-updater${TPUT_RESET}" - echo >&2 - 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." - echo >&2 "Successful updates will not send an email." - echo >&2 - ;; - "crontab") - cat "${NETDATA_SOURCE_DIR}/system/netdata.crontab" > "/etc/cron.d/netdata-updater" - - echo >&2 "Auto-updating has been enabled through cron, using a crontab at ${TPUT_RED}${TPUT_BOLD}/etc/cron.d/netdata-updater${TPUT_RESET}" - echo >&2 - 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." - echo >&2 "Successful updates will not send an email." - echo >&2 - ;; - *) - echo >&2 "Unable to determine what type of auto-update scheduling to use, not enabling auto-updates." - echo >&2 - return 1 - esac - - return 0 -} - -disable_netdata_updater() { - 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)" - echo >&2 - - if issystemd && [ -n "$(get_systemd_service_dir)" ] ; then - systemctl disable netdata-updater.timer - fi - - if [ -d /etc/cron.daily ]; then - rm -f /etc/cron.daily/netdata-updater.sh - rm -f /etc/cron.daily/netdata-updater - fi - - if [ -d /etc/periodic/daily ]; then - rm -f /etc/periodic/daily/netdata-updater.sh - rm -f /etc/periodic/daily/netdata-updater - fi - - if [ -d /etc/cron.d ]; then - rm -f /etc/cron.d/netdata-updater - fi - - return 0 -} - set_netdata_updater_channel() { sed -i -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" "${NETDATA_USER_CONFIG_DIR}/.environment" } diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh index e71d46f98f..65ffec2073 100755 --- a/packaging/installer/kickstart.sh +++ b/packaging/installer/kickstart.sh @@ -66,8 +66,9 @@ USAGE: kickstart.sh [options] --dry-run Report what we would do with the given options on this system, but don’t actually do anything. --stable-channel Install a stable version instead of a nightly build (default: install a nightly build) --nightly-channel Install a nightly build instead of a stable version - --no-updates Do not enable automatic updates (default: enable automatic updates) + --no-updates Do not enable automatic updates (default: enable automatic updates using the best supported scheduling method) --auto-update Enable automatic updates. + --auto-update-type Specify a particular scheduling type for auto-updates (valid types: systemd, interval, crontab) --disable-telemetry Opt-out of anonymous statistics. --native-only Only install if native binary packages are available. --static-only Only install if a static build is available. @@ -699,7 +700,7 @@ handle_existing_install() { ret=0 - if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then + if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ]; then if ! update; then warning "Unable to find usable updater script, not updating existing install at ${ndprefix}." fi @@ -920,6 +921,30 @@ claim() { } # ====================================================================== +# Auto-update handling code. +set_auto_updates() { + if [ -x "${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh" ]; then + updater="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh" + elif [ -x "${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh" ]; then + updater="${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh" + else + 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." + return 0 + fi + + if [ "${NETDATA_AUTO_UPDATES}" = "1" ]; then + # 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. + if ! grep -q '\-\-enable-auto-updates' ${updater}; then + echo + elif ! ${updater} --enable-auto-updates "${NETDATA_AUTO_UPDATE_TYPE}"; then + warning "Failed to enable auto updates. Netdata will still work, but you will need to update manually." + fi + else + ${updater} --disable-auto-updates + fi +} + +# ====================================================================== # Native package install code. # Check for an already installed package with a given name. @@ -1400,6 +1425,7 @@ install_on_linux() { case "$?" in 0) NETDATA_INSTALL_SUCCESSFUL=1 + INSTALL_PREFIX="/" ;; 1) fatal "Unable to install on this system." F0300 @@ -1515,6 +1541,18 @@ while [ -n "${1}" ]; do "--stable-channel") RELEASE_CHANNEL="stable" ;; "--no-updates") NETDATA_AUTO_UPDATES=0 ;; "--auto-update") NETDATA_AUTO_UPDATES="1" ;; + "--auto-update-method") + NETDATA_AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')" + case "${NETDATA_AUTO_UPDATE_TYPE}" in + systemd|interval|crontab) + shift 1 + ;; + *) + echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab" + exit 1 + ;; + esac + ;; "--reinstall") NETDATA_REINSTALL=1 ;; "--reinstall-even-if-unsafe") NETDATA_UNSAFE_REINSTALL=1 ;; "--claim-only") NETDATA_CLAIM_ONLY=1 ;; @@ -1624,6 +1662,8 @@ elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then soft_disable_cloud fi +set_auto_updates + telemetry_event INSTALL_SUCCESS "" "" cleanup trap - EXIT diff --git a/packaging/makeself/install-or-update.sh b/packaging/makeself/install-or-update.sh index 2fd7629b20..6a4cd5b971 100755 --- a/packaging/makeself/install-or-update.sh +++ b/packaging/makeself/install-or-update.sh @@ -26,7 +26,6 @@ if [ -d /opt/netdata/etc/netdata.old ]; then fi STARTIT=1 -AUTOUPDATE=0 REINSTALL_OPTIONS="" RELEASE_CHANNEL="nightly" # check .travis/create_artifacts.sh before modifying @@ -36,10 +35,7 @@ while [ "${1}" ]; do STARTIT=0 REINSTALL_OPTIONS="${REINSTALL_OPTIONS} ${1}" ;; - "--auto-update" | "-u") - AUTOUPDATE=1 - REINSTALL_OPTIONS="${REINSTALL_OPTIONS} ${1}" - ;; + "--auto-update" | "-u") ;; "--stable-channel") RELEASE_CHANNEL="stable" REINSTALL_OPTIONS="${REINSTALL_OPTIONS} ${1}" @@ -161,13 +157,6 @@ progress "Install (but not enable) netdata updater tool" cleanup_old_netdata_updater || run_failed "Cannot cleanup old netdata updater tool." install_netdata_updater || run_failed "Cannot install netdata updater tool." -progress "Check if we must enable/disable the netdata updater tool" -if [ "${AUTOUPDATE}" = "1" ]; then - enable_netdata_updater || run_failed "Cannot enable netdata updater tool" -else - disable_netdata_updater || run_failed "Cannot disable netdata updater tool" -fi - # ----------------------------------------------------------------------------- progress "creating quick links" |