diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-21 19:34:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-21 19:34:08 +0000 |
commit | 6d2e027eb728c8294fdd7c3692e9853b3ca2603b (patch) | |
tree | 3e190253238075ac8590b2f214852d2256fdad53 /packaging/installer/netdata-updater.sh | |
parent | Opting out by default from sending anonymous statistics (phone home). (diff) | |
download | netdata-6d2e027eb728c8294fdd7c3692e9853b3ca2603b.tar.xz netdata-6d2e027eb728c8294fdd7c3692e9853b3ca2603b.zip |
Merging upstream version 1.12.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'packaging/installer/netdata-updater.sh')
-rw-r--r-- | packaging/installer/netdata-updater.sh | 104 |
1 files changed, 58 insertions, 46 deletions
diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index 96f7c1270..7846ce8bf 100644 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -12,43 +12,6 @@ # - NETDATA_TARBALL_CHECKSUM_URL # - NETDATA_TARBALL_CHECKSUM - -# Usually stored in /etc/netdata/.environment -: "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}" - -# shellcheck source=/dev/null -source "${ENVIRONMENT_FILE}" || exit 1 - -if [ "${INSTALL_UID}" != "$(id -u)" ]; then - echo >&2 "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)" - exit 1 -fi - -# signal netdata to start saving its database -# this is handy if your database is big -pids=$(pidof netdata) -do_not_start= -if [ -n "${pids}" ]; then - #shellcheck disable=SC2086 - kill -USR1 ${pids} -else - # netdata is currently not running, so do not start it after updating - do_not_start="--dont-start-it" -fi - -tmp= -if [ -t 2 ]; then - # we are running on a terminal - # open fd 3 and send it to stderr - exec 3>&2 -else - # we are headless - # create a temporary file for the log - tmp=$(mktemp /tmp/netdata-updater.log.XXXXXX) - # open fd 3 and send it to tmp - exec 3>"${tmp}" -fi - info() { echo >&3 "$(date) : INFO: " "${@}" } @@ -61,19 +24,31 @@ error() { failed() { error "FAILED TO UPDATE NETDATA : ${1}" - if [ -n "${tmp}" ]; then - cat >&2 "${tmp}" - rm "${tmp}" + if [ -n "${logfile}" ]; then + cat >&2 "${logfile}" + rm "${logfile}" fi exit 1 } +download() { + url="${1}" + dest="${2}" + if command -v curl >/dev/null 2>&1; then + curl -L --connect-timeout 5 --retry 3 "${url}" >"${dest}" || fatal "Cannot download ${url}" + elif command -v wget >/dev/null 2>&1; then + wget -T 15 -O - "${url}" >"${dest}" || fatal "Cannot download ${url}" + else + failed "I need curl or wget to proceed, but neither is available on this system." + fi +} + update() { - [ -z "${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)" + [ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)" # Check if tmp is mounted as noexec if grep -Eq '^[^ ]+ /tmp [^ ]+ ([^ ]*,)?noexec[, ]' /proc/mounts; then - pattern="/opt/netdata-updater-XXXXXX" + pattern="$(pwd)/netdata-updater-XXXXXX" else pattern="/tmp/netdata-updater-XXXXXX" fi @@ -82,13 +57,13 @@ update() { cd "$dir" - wget "${NETDATA_TARBALL_CHECKSUM_URL}" -O sha256sum.txt >&3 2>&3 + download "${NETDATA_TARBALL_CHECKSUM_URL}" "${dir}/sha256sum.txt" >&3 2>&3 if grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then info "Newest version is already installed" exit 0 fi - wget "${NETDATA_TARBALL_URL}" -O netdata-latest.tar.gz >&3 2>&3 + download "${NETDATA_TARBALL_URL}" "${dir}/netdata-latest.tar.gz" if ! grep netdata-latest.tar.gz sha256sum.txt | sha256sum --check - >&3 2>&3; then failed "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${dir}" fi @@ -97,8 +72,20 @@ update() { rm netdata-latest.tar.gz >&3 2>&3 cd netdata-* + # signal netdata to start saving its database + # this is handy if your database is big + pids=$(pidof netdata) + do_not_start= + if [ -n "${pids}" ]; then + #shellcheck disable=SC2086 + kill -USR1 ${pids} + else + # netdata is currently not running, so do not start it after updating + do_not_start="--dont-start-it" + fi + info "Re-installing netdata..." - ${REINSTALL_COMMAND} --dont-wait ${do_not_start} >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA" + eval "${REINSTALL_COMMAND} --dont-wait ${do_not_start}" >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA" sed -i '/NETDATA_TARBALL/d' "${ENVIRONMENT_FILE}" cat <<EOF >>"${ENVIRONMENT_FILE}" NETDATA_TARBALL_URL="$NETDATA_TARBALL_URL" @@ -107,9 +94,34 @@ NETDATA_TARBALL_CHECKSUM="$NEW_CHECKSUM" EOF rm -rf "${dir}" >&3 2>&3 - [ -n "${tmp}" ] && rm "${tmp}" && tmp= + [ -n "${logfile}" ] && rm "${logfile}" && logfile= return 0 } +# Usually stored in /etc/netdata/.environment +: "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}" + +# shellcheck source=/dev/null +source "${ENVIRONMENT_FILE}" || exit 1 + +if [ "${INSTALL_UID}" != "$(id -u)" ]; then + echo >&2 "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)" + exit 1 +fi + +logfile= +if [ -t 2 ]; then + # we are running on a terminal + # open fd 3 and send it to stderr + exec 3>&2 +else + # we are headless + # create a temporary file for the log + logfile=$(mktemp ${logfile}/netdata-updater.log.XXXXXX) + # open fd 3 and send it to logfile + exec 3>"${logfile}" +fi + + # the installer updates this script - so we run and exit in a single line update && exit 0 |