summaryrefslogtreecommitdiffstats
path: root/packaging/installer
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-02-21 19:34:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-02-21 19:34:08 +0000
commit6d2e027eb728c8294fdd7c3692e9853b3ca2603b (patch)
tree3e190253238075ac8590b2f214852d2256fdad53 /packaging/installer
parentOpting out by default from sending anonymous statistics (phone home). (diff)
downloadnetdata-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')
-rw-r--r--packaging/installer/README.md6
-rw-r--r--packaging/installer/UNINSTALL.md11
-rw-r--r--packaging/installer/UPDATE.md6
-rw-r--r--packaging/installer/functions.sh4
-rwxr-xr-xpackaging/installer/kickstart-static64.sh303
-rwxr-xr-xpackaging/installer/kickstart.sh10
-rwxr-xr-xpackaging/installer/netdata-uninstaller.sh169
-rw-r--r--packaging/installer/netdata-updater.sh104
8 files changed, 188 insertions, 425 deletions
diff --git a/packaging/installer/README.md b/packaging/installer/README.md
index eb507a5fc..14b16bd45 100644
--- a/packaging/installer/README.md
+++ b/packaging/installer/README.md
@@ -41,7 +41,7 @@ bash <(curl -Ss https://my-netdata.io/kickstart.sh)
Verify the integrity of the script with this:
```bash
-[ "b4632ca6c651de0f667e6d4f6e1015fe" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
+[ "7d16639b6ee14b0a33a8b90c979d3513" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
```
*It should print `OK, VALID` if the script is the one we ship.*
@@ -95,7 +95,7 @@ To install Netdata with a binary package on any Linux distro, any kernel version
Verify the integrity of the script with this:
```bash
-[ "ac8e5cf25399b08c42d37e1a53e1a6d3" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
+[ "61ed714ebe0edf03e90cb5cef59fa991" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
```
*It should print `OK, VALID` if the script is the one we ship.*
@@ -250,6 +250,8 @@ cd netdata
* If you don't want to install it on the default directories, you can run the installer like this: `./netdata-installer.sh --install /opt`. This one will install Netdata in `/opt/netdata`.
+* If your server does not have access to the internet and you have manually put the installation directory on your server, you will need to pass the option `--disable-go` to the installer. The option will prevent the installer from attempting to download and install `go.d.plugin`.
+
Once the installer completes, the file `/etc/netdata/netdata.conf` will be created (if you changed the installation directory, the configuration will appear in that directory too).
You can edit this file to set options. One common option to tweak is `history`, which controls the size of the memory database Netdata will use. By default is `3600` seconds (an hour of data at the charts) which makes Netdata use about 10-15MB of RAM (depending on the number of charts detected on your system). Check **[[Memory Requirements]]**.
diff --git a/packaging/installer/UNINSTALL.md b/packaging/installer/UNINSTALL.md
index 511693b48..e86a3390e 100644
--- a/packaging/installer/UNINSTALL.md
+++ b/packaging/installer/UNINSTALL.md
@@ -8,14 +8,19 @@ NETDATA_ADDED_TO_GROUPS
A workflow for uninstallation looks like this:
-1. Find your .environment file
+1. Find your `.environment` file, which is usually `/etc/netdata/.environment` in a default installation.
2. If you cannot find that file and would like to uninstall netdata, then create new file with following content:
```
NETDATA_PREFIX="<installation prefix>" # put what you used as a parameter to shell installed `--install` flag. Otherwise it should be empty
NETDATA_ADDED_TO_GROUPS="<additional groups>" # Additional groups for a user running netdata process
```
-3. Download [netdata-uninstaller.sh](https://github.com/netdata/netdata/blob/master/packaging/installer/netdata-uninstaller.sh) and run it as follows: `netdata-uninstaller.sh --yes --env <path_to_environment_file>`. The default `path_to_environment_file` is `/etc/netdata`, it's the location of the file `.environment` that is used by the uninstaller.
-
+3. Download, chmod and run netdata-uninstaller.sh.
+```
+wget https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-uninstaller.sh
+chmod +x ./netdata-uninstaller.sh
+./netdata-uninstaller.sh --yes --env <environment_file>
+```
+The default `environment_file` is `/etc/netdata/.environment`.
Note: This uninstallation method assumes previous installation with netdata-installer.sh or kickstart script. Currently using it when netdata was installed by a package manager can work or cause unexpected results.
diff --git a/packaging/installer/UPDATE.md b/packaging/installer/UPDATE.md
index 7c0be8323..c93ebf9b4 100644
--- a/packaging/installer/UPDATE.md
+++ b/packaging/installer/UPDATE.md
@@ -32,7 +32,7 @@ Keep in mind, netdata may now have new features, or certain old features may now
The `kickstart.sh` one-liner will do a one-time update to the latest nightly build, if executed as follows:
```
-bash <(curl -Ss https://my-netdata.io/kickstart.sh --no-updates)
+bash <(curl -Ss https://my-netdata.io/kickstart.sh) --no-updates
```
### Auto-update
@@ -47,9 +47,9 @@ Note that after Jan 2019, the `kickstart.sh` one-liner `bash <(curl -Ss https://
## You downloaded a binary package
-If you installed it from a binary package, the best way is to **obtain a newer copy** from the source you got it in the first place.
+If you installed it from a binary package, the best way is to **obtain a newer copy** from the source you got it in the first place. This includes the static binary installation via `kickstart-base64.sh`, which would need to be executed again.
-If a newer version of netdata is not available from the source you got it, we suggest to uninstall the version you have and follow the **[[Installation]]** instructions for installing a fresh version of netdata.
+If a newer version of netdata is not available from the source you got it, we suggest to uninstall the version you have and follow the [installation](README.md) instructions for installing a fresh version of netdata.
[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Finstaller%2FUPDATE&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]()
diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh
index a2d7365ea..0d0450842 100644
--- a/packaging/installer/functions.sh
+++ b/packaging/installer/functions.sh
@@ -189,6 +189,10 @@ portable_find_processors() {
portable_find_processors
# -----------------------------------------------------------------------------
+fatal() {
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
+ exit 1
+}
run_ok() {
printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
diff --git a/packaging/installer/kickstart-static64.sh b/packaging/installer/kickstart-static64.sh
index cd13c4190..3a6b2653e 100755
--- a/packaging/installer/kickstart-static64.sh
+++ b/packaging/installer/kickstart-static64.sh
@@ -1,238 +1,149 @@
#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
-# shellcheck disable=SC1117,SC2016,SC2034,SC2039,SC2059,SC2086,SC2119,SC2120,SC2129,SC2162,SC2166,SC2181
+# shellcheck disable=SC1117,SC2039,SC2059,SC2086
-umask 022
-
-# make sure UID is set
-# shellcheck disable=SC2155
-[ -z "${UID}" ] && export UID="$(id -u)"
+# External files
+NIGHTLY_PACKAGE_TARBALL="https://storage.googleapis.com/netdata-nightlies/netdata-latest.gz.run"
+NIGHTLY_PACKAGE_CHECKSUM="https://storage.googleapis.com/netdata-nightlies/sha256sums.txt"
# ---------------------------------------------------------------------------------------------------------------------
# library functions copied from packaging/installer/functions.sh
-which_cmd() {
- # shellcheck disable=SC2230
- which "${1}" 2>/dev/null || command -v "${1}" 2>/dev/null
-}
-
-check_cmd() {
- which_cmd "${1}" >/dev/null 2>&1 && return 0
- return 1
-}
-
setup_terminal() {
- TPUT_RESET=""
- TPUT_BLACK=""
- TPUT_RED=""
- TPUT_GREEN=""
- TPUT_YELLOW=""
- TPUT_BLUE=""
- TPUT_PURPLE=""
- TPUT_CYAN=""
- TPUT_WHITE=""
- TPUT_BGBLACK=""
- TPUT_BGRED=""
- TPUT_BGGREEN=""
- TPUT_BGYELLOW=""
- TPUT_BGBLUE=""
- TPUT_BGPURPLE=""
- TPUT_BGCYAN=""
- TPUT_BGWHITE=""
- TPUT_BOLD=""
- TPUT_DIM=""
- TPUT_UNDERLINED=""
- TPUT_BLINK=""
- TPUT_INVERTED=""
- TPUT_STANDOUT=""
- TPUT_BELL=""
- TPUT_CLEAR=""
-
- # Is stderr on the terminal? If not, then fail
- test -t 2 || return 1
-
- if check_cmd tput
- then
- if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
- then
- # Enable colors
- TPUT_RESET="$(tput sgr 0)"
- TPUT_BLACK="$(tput setaf 0)"
- TPUT_RED="$(tput setaf 1)"
- TPUT_GREEN="$(tput setaf 2)"
- TPUT_YELLOW="$(tput setaf 3)"
- TPUT_BLUE="$(tput setaf 4)"
- TPUT_PURPLE="$(tput setaf 5)"
- TPUT_CYAN="$(tput setaf 6)"
- TPUT_WHITE="$(tput setaf 7)"
- TPUT_BGBLACK="$(tput setab 0)"
- TPUT_BGRED="$(tput setab 1)"
- TPUT_BGGREEN="$(tput setab 2)"
- TPUT_BGYELLOW="$(tput setab 3)"
- TPUT_BGBLUE="$(tput setab 4)"
- TPUT_BGPURPLE="$(tput setab 5)"
- TPUT_BGCYAN="$(tput setab 6)"
- TPUT_BGWHITE="$(tput setab 7)"
- TPUT_BOLD="$(tput bold)"
- TPUT_DIM="$(tput dim)"
- TPUT_UNDERLINED="$(tput smul)"
- TPUT_BLINK="$(tput blink)"
- TPUT_INVERTED="$(tput rev)"
- TPUT_STANDOUT="$(tput smso)"
- TPUT_BELL="$(tput bel)"
- TPUT_CLEAR="$(tput clear)"
- fi
- fi
-
- return 0
+ TPUT_RESET=""
+ TPUT_YELLOW=""
+ TPUT_WHITE=""
+ TPUT_BGRED=""
+ TPUT_BGGREEN=""
+ TPUT_BOLD=""
+ TPUT_DIM=""
+
+ # Is stderr on the terminal? If not, then fail
+ test -t 2 || return 1
+
+ if command -v tput >/dev/null 2>&1; then
+ if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
+ # Enable colors
+ TPUT_RESET="$(tput sgr 0)"
+ TPUT_YELLOW="$(tput setaf 3)"
+ TPUT_WHITE="$(tput setaf 7)"
+ TPUT_BGRED="$(tput setab 1)"
+ TPUT_BGGREEN="$(tput setab 2)"
+ TPUT_BOLD="$(tput bold)"
+ TPUT_DIM="$(tput dim)"
+ fi
+ fi
+
+ return 0
}
-setup_terminal || echo >/dev/null
progress() {
- echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
-}
-
-run_ok() {
- printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
-}
-
-run_failed() {
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
+ echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
}
-ESCAPED_PRINT_METHOD=
-printf "%q " test >/dev/null 2>&1
-[ $? -eq 0 ] && ESCAPED_PRINT_METHOD="printfq"
escaped_print() {
- if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]
- then
- printf "%q " "${@}"
- else
- printf "%s" "${*}"
- fi
- return 0
+ if printf "%q " test >/dev/null 2>&1; then
+ printf "%q " "${@}"
+ else
+ printf "%s" "${*}"
+ fi
+ return 0
}
-run_logfile="/dev/null"
run() {
- local user="${USER--}" dir="${PWD}" info info_console
-
- if [ "${UID}" = "0" ]
- then
- info="[root ${dir}]# "
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
- else
- info="[${user} ${dir}]$ "
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
- fi
-
- printf >> "${run_logfile}" "${info}"
- escaped_print >> "${run_logfile}" "${@}"
- printf >> "${run_logfile}" " ... "
-
- printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
- escaped_print >&2 "${@}"
- printf >&2 "${TPUT_RESET}\n"
-
- "${@}"
-
- local ret=$?
- if [ ${ret} -ne 0 ]
- then
- run_failed
- printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
- else
- run_ok
- printf >> "${run_logfile}" "OK\n"
- fi
-
- return ${ret}
-}
+ local dir="${PWD}" info_console
+ if [ "${UID}" = "0" ]; then
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
+ else
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
+ fi
-# ---------------------------------------------------------------------------------------------------------------------
+ escaped_print "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" "${@}" "${TPUT_RESET}\n" >&2
-fatal() {
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
- exit 1
+ "${@}"
+
+ local ret=$?
+ if [ ${ret} -ne 0 ]; then
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
+ else
+ printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
+ fi
+
+ return ${ret}
}
# ---------------------------------------------------------------------------------------------------------------------
-if [ "$(uname -m)" != "x86_64" ]
- then
- fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
-fi
+fatal() {
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
+ exit 1
+}
-if [ "$(uname -s)" != "Linux" ]
- then
- fatal "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
-fi
+download() {
+ url="${1}"
+ dest="${2}"
+ if command -v curl >/dev/null 2>&1; then
+ run curl -L --connect-timeout 5 --retry 3 "${url}" >"${dest}" || fatal "Cannot download ${url}"
+ elif command -v wget >/dev/null 2>&1; then
+ run wget -T 15 -O - "${url}" >"${dest}" || fatal "Cannot download ${url}"
+ else
+ fatal "I need curl or wget to proceed, but neither is available on this system."
+ fi
+}
-curl="$(which_cmd curl)"
-wget="$(which_cmd wget)"
+umask 022
-# ---------------------------------------------------------------------------------------------------------------------
+sudo=""
+[ -z "${UID}" ] && UID="$(id -u)"
+[ "${UID}" -ne "0" ] && sudo="sudo"
-progress "Checking the latest version of static build..."
+setup_terminal || echo >/dev/null
-BASE='https://raw.githubusercontent.com/netdata/binary-packages/master'
+# ---------------------------------------------------------------------------------------------------------------------
-LATEST=
-if [ ! -z "${curl}" -a -x "${curl}" ]
-then
- LATEST="$(run ${curl} "${BASE}/netdata-latest.gz.run")"
-elif [ ! -z "${wget}" -a -x "${wget}" ]
-then
- LATEST="$(run ${wget} -O - "${BASE}/netdata-latest.gz.run")"
-else
- fatal "curl or wget are needed for this script to work."
+if [ "$(uname -m)" != "x86_64" ]; then
+ fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
fi
-if [ -z "${LATEST}" ]
- then
- fatal "Cannot find the latest static binary version of netdata."
+if [ "$(uname -s)" != "Linux" ]; then
+ fatal "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)"
fi
# ---------------------------------------------------------------------------------------------------------------------
-progress "Downloading static netdata binary: ${LATEST}"
-
-ret=1
-if [ ! -z "${curl}" -a -x "${curl}" ]
-then
- run ${curl} "${BASE}/${LATEST}" >"/tmp/${LATEST}"
- ret=$?
-elif [ ! -z "${wget}" -a -x "${wget}" ]
-then
- run ${wget} -O "/tmp/${LATEST}" "${BASE}/${LATEST}"
- ret=$?
+# Check if tmp is mounted as noexec
+if grep -Eq '^[^ ]+ /tmp [^ ]+ ([^ ]*,)?noexec[, ]' /proc/mounts; then
+ pattern="$(pwd)/netdata-kickstart-static-XXXXXX"
else
- fatal "curl or wget are needed for this script to work."
+ pattern="/tmp/netdata-kickstart-static-XXXXXX"
fi
-if [ ${ret} -ne 0 -o ! -s "/tmp/${LATEST}" ]
- then
- fatal "Failed to download the latest static binary version of netdata."
+tmpdir="$(mktemp -d $pattern)"
+cd "${tmpdir}" || :
+
+progress "Downloading static netdata binary: ${NIGHTLY_PACKAGE_TARBALL}"
+
+download "${NIGHTLY_PACKAGE_CHECKSUM}" "${tmpdir}/sha256sum.txt"
+download "${NIGHTLY_PACKAGE_TARBALL}" "${tmpdir}/netdata-latest.gz.run"
+if ! grep netdata-latest.gz.run sha256sum.txt | sha256sum --check - >/dev/null 2>&1; then
+ failed "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${tmpdir}"
fi
# ---------------------------------------------------------------------------------------------------------------------
opts=
inner_opts=
-while [ ! -z "${1}" ]
-do
- if [ "${1}" = "--dont-wait" -o "${1}" = "--non-interactive" -o "${1}" = "--accept" ]
- then
- opts="${opts} --accept"
- elif [ "${1}" = "--dont-start-it" ]
- then
- inner_opts="${inner_opts} ${1}"
- else
- echo >&2 "Unknown option '${1}'"
- exit 1
- fi
- shift
+while [ ! -z "${1}" ]; do
+ if [ "${1}" = "--dont-wait" ] || [ "${1}" = "--non-interactive" ] || [ "${1}" = "--accept" ]; then
+ opts="${opts} --accept"
+ elif [ "${1}" = "--dont-start-it" ]; then
+ inner_opts="${inner_opts} ${1}"
+ else
+ echo >&2 "Unknown option '${1}'"
+ exit 1
+ fi
+ shift
done
[ ! -z "${inner_opts}" ] && inner_opts="-- ${inner_opts}"
@@ -240,13 +151,11 @@ done
progress "Installing netdata"
-sudo=
-[ "${UID}" != "0" ] && sudo="sudo"
-run ${sudo} sh "/tmp/${LATEST}" ${opts} ${inner_opts}
+run ${sudo} sh "${tmpdir}/netdata-latest.gz.run" ${opts} ${inner_opts}
-if [ $? -eq 0 ]
- then
- rm "/tmp/${LATEST}"
+#shellcheck disable=SC2181
+if [ $? -eq 0 ]; then
+ rm "${tmpdir}/netdata-latest.gz.run"
else
- echo >&2 "NOTE: did not remove: /tmp/${LATEST}"
+ echo >&2 "NOTE: did not remove: ${tmpdir}/netdata-latest.gz.run"
fi
diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh
index 2a5c874da..9a5e848ba 100755
--- a/packaging/installer/kickstart.sh
+++ b/packaging/installer/kickstart.sh
@@ -115,10 +115,10 @@ fatal() {
download() {
url="${1}"
dest="${2}"
- if command -v wget >/dev/null 2>&1; then
- run wget -O - "${url}" >"${dest}" || fatal "Cannot download ${url}"
- elif command -v curl >/dev/null 2>&1; then
- run curl "${url}" >"${dest}" || fatal "Cannot download ${url}"
+ if command -v curl >/dev/null 2>&1; then
+ run curl -L --connect-timeout 5 --retry 3 "${url}" >"${dest}" || fatal "Cannot download ${url}"
+ elif command -v wget >/dev/null 2>&1; then
+ run wget -T 15 -O - "${url}" >"${dest}" || fatal "Cannot download ${url}"
else
fatal "I need curl or wget to proceed, but neither is available on this system."
fi
@@ -218,7 +218,7 @@ EOF
# Check if tmp is mounted as noexec
if grep -Eq '^[^ ]+ /tmp [^ ]+ ([^ ]*,)?noexec[, ]' /proc/mounts; then
- pattern="/opt/netdata-kickstart-XXXXXX"
+ pattern="$(pwd)/netdata-kickstart-XXXXXX"
else
pattern="/tmp/netdata-kickstart-XXXXXX"
fi
diff --git a/packaging/installer/netdata-uninstaller.sh b/packaging/installer/netdata-uninstaller.sh
deleted file mode 100755
index 96dd62906..000000000
--- a/packaging/installer/netdata-uninstaller.sh
+++ /dev/null
@@ -1,169 +0,0 @@
-#!/usr/bin/env bash
-#shellcheck disable=SC2181
-
-# this script will uninstall netdata
-
-# Variables needed by script and taken from '.environment' file:
-# - NETDATA_PREFIX
-# - NETDATA_ADDED_TO_GROUPS
-
-usage="$(basename "$0") [-h] [-f ] -- program to calculate the answer to life, the universe and everything
-
-where:
- -e, --env path to environment file (defauls to '/etc/netdata/.environment'
- -f, --force force uninstallation and do not ask any questions
- -h show this help text
- -y, --yes flag needs to be set to proceed with uninstallation"
-
-FILE_REMOVAL_STATUS=0
-ENVIRONMENT_FILE="/etc/netdata/.environment"
-INTERACTIVITY="-i"
-YES=0
-while :; do
- case "$1" in
- -h | --help)
- echo "$usage" >&2
- exit 1
- ;;
- -f | --force)
- INTERACTIVITY="-f"
- shift
- ;;
- -y | --yes)
- YES=1
- shift
- ;;
- -e | --env)
- ENVIRONMENT_FILE="$2"
- shift 2
- ;;
- -*)
- echo "$usage" >&2
- exit 1
- ;;
- *) break ;;
- esac
-done
-
-if [ "$YES" != "1" ]; then
- echo "This script will REMOVE netdata from your system."
- echo "Run it again with --yes to do it."
- exit 1
-fi
-
-if [[ $EUID -ne 0 ]]; then
- echo "This script SHOULD be run as root or otherwise it won't delete all installed components."
- key="n"
- read -r -s -n 1 -p "Do you want to continue as non-root user [y/n] ? " key
- if [ "$key" != "y" ] && [ "$key" != "Y" ]; then
- exit 1
- fi
-fi
-
-function quit_msg() {
- echo
- if [ "$FILE_REMOVAL_STATUS" -eq 0 ]; then
- echo "Something went wrong :("
- else
- echo "Netdata files were successfully removed from your system"
- fi
-}
-
-function user_input() {
- TEXT="$1"
- if [ "${INTERACTIVITY}" == "-i" ]; then
- read -r -p "$TEXT" >&2
- fi
-}
-
-function rm_file() {
- FILE="$1"
- if [ -f "${FILE}" ]; then
- rm -v ${INTERACTIVITY} "${FILE}"
- fi
-}
-
-function rm_dir() {
- DIR="$1"
- if [ -n "$DIR" ] && [ -d "$DIR" ]; then
- user_input "Press ENTER to recursively delete directory '$DIR' > "
- rm -v -f -R "${DIR}"
- fi
-}
-
-netdata_pids() {
- local p myns ns
- myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
- for p in \
- $(cat /var/run/netdata.pid 2>/dev/null) \
- $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
- $(pidof netdata 2>/dev/null); do
-
- ns="$(readlink "/proc/${p}/ns/pid" 2>/dev/null)"
- #shellcheck disable=SC2002
- if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
- name="$(cat "/proc/${p}/stat" 2>/dev/null | cut -d '(' -f 2 | cut -d ')' -f 1)"
- if [ "${name}" = "netdata" ]; then
- echo "${p}"
- fi
- fi
- done
-}
-
-trap quit_msg EXIT
-
-#shellcheck source=/dev/null
-source "${ENVIRONMENT_FILE}" || exit 1
-
-#### STOP NETDATA
-echo "Stopping a possibly running netdata..."
-for p in $(netdata_pids); do
- i=0
- while kill "${p}" 2>/dev/null; do
- if [ "$i" -gt 30 ]; then
- echo "Forcefully stopping netdata with pid ${p}"
- kill -9 "${p}"
- sleep 2
- break
- fi
- sleep 1
- i=$((i + 1))
- done
-done
-sleep 2
-
-#### REMOVE NETDATA FILES
-rm_file /etc/logrotate.d/netdata
-rm_file /etc/systemd/system/netdata.service
-rm_file /lib/systemd/system/netdata.service
-rm_file /usr/lib/systemd/system/netdata.service
-rm_file /etc/init.d/netdata
-rm_file /etc/periodic/daily/netdata-updater
-rm_file /etc/cron.daily/netdata-updater
-
-if [ -n "${NETDATA_PREFIX}" ] && [ -d "${NETDATA_PREFIX}" ]; then
- rm_dir "${NETDATA_PREFIX}"
-else
- rm_file "/usr/sbin/netdata"
- rm_dir "/usr/share/netdata"
- rm_dir "/usr/libexec/netdata"
- rm_dir "/var/lib/netdata"
- rm_dir "/var/cache/netdata"
- rm_dir "/var/log/netdata"
- rm_dir "/etc/netdata"
-fi
-
-FILE_REMOVAL_STATUS=1
-
-#### REMOVE NETDATA USER & GROUP
-if [ -n "$NETDATA_ADDED_TO_GROUPS" ]; then
- user_input "Press ENTER to delete 'netdata' from following groups: '$NETDATA_ADDED_TO_GROUPS' > "
- for group in $NETDATA_ADDED_TO_GROUPS; do
- gpasswd -d netdata "${group}"
- done
-fi
-
-user_input "Press ENTER to delete 'netdata' system user > "
-userdel -f netdata || :
-user_input "Press ENTER to delete 'netdata' system group > "
-groupdel -f netdata || :
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