@cryptotaxi247 / netdata-1 / commits / 0fc101679

Correctly propagate errors and warnings up to the kickstart script from scripts it calls. (#12686)

* Overhaul deferred error handling in netdata-installer.sh * Propagate errors from netdata-installer.sh properly to the kickstart script. * Propagate errors from netdata-updater.sh properly to the kickstart script. * Overhaul logging in uninstaller and integrate with error propagation in kickstart.sh. * Fix name of variable used for propagating warnings. * Fix handling of run_ok and run_failed with no arguments. * Fix environment file validation in updater. * Add debugging info to CI. * Properly accept empty NETDATA_PREFIX in updater. * Convert remaining unguarded unsuccessful exits in updater to use fatal. * Fix usage of `env` in updater.

Austin S. Hemmelgarn committed Apr 27, 2022 at 07:44 UTC 0fc101679dcd12f1cb8acdd07bb4c85d8e553e53
6 files changed +319 -242
.github/scripts/run-updater-check.sh
+3
@@ -2,6 +2,9 @@
2
3 echo ">>> Installing Netdata..."
4 /netdata/packaging/installer/kickstart.sh --dont-wait --build-only --disable-telemetry || exit 1
5 +echo "::group::Environment File Contents"
6 +cat /etc/netdata/.environment
7 +echo "::endgroup::"
8 echo ">>> Updating Netdata..."
9 export NETDATA_NIGHTLIES_BASEURL="http://localhost:8080/artifacts/" # Pull the tarball from the local web server.
10 /netdata/packaging/installer/netdata-updater.sh --not-running-from-cron --no-updater-self-update || exit 1
netdata-installer.sh
+101 -148
@@ -2,6 +2,8 @@
2
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 +# Next unused error code: I0012
6 +
7 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
8 uniquepath() {
9 path=""
@@ -37,6 +39,21 @@ fi
39 # make sure /etc/profile does not change our current directory
40 cd "${NETDATA_SOURCE_DIR}" || exit 1
41
42 +# -----------------------------------------------------------------------------
43 +# load the required functions
44 +
45 +if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
46 + # shellcheck source=packaging/installer/functions.sh
47 + . "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
48 +else
49 + # shellcheck source=packaging/installer/functions.sh
50 + . "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
51 +fi
52 +
53 +# Used to enable saved warnings support in functions.sh
54 +# shellcheck disable=SC2034
55 +NETDATA_SAVE_WARNINGS=1
56 +
57 # -----------------------------------------------------------------------------
58 # figure out an appropriate temporary directory
59 _cannot_use_tmpdir() {
@@ -62,9 +79,7 @@ _cannot_use_tmpdir() {
79 if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
80 if _cannot_use_tmpdir /tmp; then
81 if _cannot_use_tmpdir "${PWD}"; then
65 - echo >&2
66 - echo >&2 "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again."
67 - exit 1
82 + fatal "UUnable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." I0000
83 else
84 TMPDIR="${PWD}"
85 fi
@@ -75,36 +90,18 @@ fi
90
91 # -----------------------------------------------------------------------------
92 # set up handling for deferred error messages
78 -NETDATA_DEFERRED_ERRORS=""
79 -
80 -defer_error() {
81 - NETDATA_DEFERRED_ERRORS="${NETDATA_DEFERRED_ERRORS}\n* ${1}"
82 -}
83 -
84 -defer_error_highlighted() {
85 - NETDATA_DEFERRED_ERRORS="${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_DEFERRED_ERRORS}\n* ${1}${TPUT_RESET}"
86 -}
93 +#
94 +# This leverages the saved warnings functionality shared with some functions from functions.sh
95
96 print_deferred_errors() {
89 - if [ -n "${NETDATA_DEFERRED_ERRORS}" ]; then
90 - echo >&2
91 - echo >&2 "The following non-fatal errors were encountered during the installation process:"
92 - printf '%s' >&2 "${NETDATA_DEFERRED_ERRORS}"
93 - echo >&2
97 + if [ -n "${SAVED_WARNINGS}" ]; then
98 + printf >&2 "\n"
99 + printf >&2 "%s\n" "The following warnings and non-fatal errors were encountered during the installation process:"
100 + printf >&2 "%s\n" "${SAVED_WARNINGS}"
101 + printf >&2 "\n"
102 fi
103 }
104
97 -# -----------------------------------------------------------------------------
98 -# load the required functions
99 -
100 -if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
101 - # shellcheck source=packaging/installer/functions.sh
102 - . "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
103 -else
104 - # shellcheck source=packaging/installer/functions.sh
105 - . "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
106 -fi
107 -
105 download_go() {
106 download_file "${1}" "${2}" "go.d plugin" "go"
107 }
@@ -159,7 +156,7 @@ banner_nonroot_install() {
156
157 ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
158
162 - You are attempting to install netdata as non-root, but you plan
159 + You are attempting to install netdata as a non-root user, but you plan
160 to install it in system paths.
161
162 Please set an installation prefix, like this:
@@ -346,7 +343,7 @@ while [ -n "${1}" ]; do
343 "--one-time-build") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-dependency-tracking)}" | sed 's/$/ --disable-dependency-tracking/g')" ;;
344 "--disable-cloud")
345 if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
349 - echo "Cloud explicitly enabled, ignoring --disable-cloud."
346 + warning "Cloud explicitly enabled, ignoring --disable-cloud."
347 else
348 NETDATA_DISABLE_CLOUD=1
349 NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-cloud)}" | sed 's/$/ --disable-cloud/g')"
@@ -354,7 +351,7 @@ while [ -n "${1}" ]; do
351 ;;
352 "--require-cloud")
353 if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
357 - echo "Cloud explicitly disabled, ignoring --require-cloud."
354 + warning "Cloud explicitly disabled, ignoring --require-cloud."
355 else
356 NETDATA_REQUIRE_CLOUD=1
357 NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-cloud)}" | sed 's/$/ --enable-cloud/g')"
@@ -379,7 +376,8 @@ while [ -n "${1}" ]; do
376 exit 1
377 ;;
378 *)
382 - run_failed "I cannot understand option '$1'."
379 + echo >&2 "Unrecognized option '${1}'."
380 + exit_reason "Unrecognized option '${1}'." I000E
381 usage
382 exit 1
383 ;;
@@ -434,8 +432,8 @@ if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
432 if [ "${target_ram}" -gt "${total_ram}" ] && [ "${proc_count}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
433 target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
434 total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
437 - run_failed "Netdata needs ${target_ram} of RAM to safely install, but this system only has ${total_ram}."
438 - run_failed "Insufficient RAM available for an install. Try reducing the number of processes used for the install using the \$MAKEOPTS variable."
435 + run_failed "Netdata needs ${target_ram} of RAM to safely install, but this system only has ${total_ram}. Try reducing the number of processes used for the install using the \$MAKEOPTS variable."
436 + exit_reason "Insufficent RAM to safely install." I000F
437 exit 2
438 fi
439 fi
@@ -451,8 +449,8 @@ fi
449 if [ "$(id -u)" -ne 0 ]; then
450 if [ -z "${NETDATA_PREFIX}" ]; then
451 netdata_banner
454 - progress "wrong command line options!"
452 banner_nonroot_install "${@}"
453 + exit_reason "Attempted install as non-root user to /." I0010
454 exit 1
455 else
456 banner_root_notify "${@}"
@@ -535,18 +533,7 @@ if [ ! "$have_autotools" ]; then
533 if [ -f configure ]; then
534 echo "Will skip autoreconf step"
535 else
538 - netdata_banner
539 - progress "autotools v2.60 required"
540 - cat << "EOF"
541 -
542 --------------------------------------------------------------------------------
543 -autotools 2.60 or later is required
544 -
545 -Sorry, you do not seem to have autotools 2.60 or later, which is
546 -required to build from the git sources of netdata.
547 -
548 -EOF
549 - exit 1
536 + fatal "Could not find a usable version of GNU autotools, which is required for building Netdata. Version 2.60 or later of GNU autotools is required." I0001
537 fi
538 fi
539
@@ -558,6 +545,7 @@ if [ ${DONOTWAIT} -eq 0 ]; then
545 fi
546 read -r REPLY
547 if [ "$REPLY" != '' ]; then
548 + exit_reason "User did not accept install attempt." I0011
549 exit 1
550 fi
551
@@ -565,44 +553,8 @@ fi
553
554 build_error() {
555 netdata_banner
568 - progress "sorry, it failed to build..."
569 - cat << EOF
570 -
571 -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
572 -
573 -Sorry! netdata failed to build...
574 -
575 -You may need to check these:
576 -
577 -1. The package uuid-dev (or libuuid-devel) has to be installed.
578 -
579 - If your system cannot find libuuid, although it is installed
580 - run me with the option: --libs-are-really-here
581 -
582 -2. The package zlib1g-dev (or zlib-devel) has to be installed.
583 -
584 - If your system cannot find zlib, although it is installed
585 - run me with the option: --libs-are-really-here
586 -
587 -3. The package json-c-dev (or json-c-devel) has to be installed.
588 -
589 - If your system cannot find json-c, although it is installed
590 - run me with the option: --libs-are-really-here
591 -
592 -4. You need basic build tools installed, like:
593 -
594 - gcc make autoconf automake pkg-config
595 -
596 - Autoconf version 2.60 or higher is required.
597 -
598 -If you still cannot get it to build, ask for help at github:
599 -
600 - https://github.com/netdata/netdata/issues
601 -
602 -
603 -EOF
556 trap - EXIT
605 - exit 1
557 + fatal "Netdata failed to build for an unknown reason." I0002
558 }
559
560 if [ ${LIBS_ARE_HERE} -eq 1 ]; then
@@ -655,7 +607,7 @@ bundle_protobuf() {
607
608 if [ -n "${USE_SYSTEM_PROTOBUF}" ]; then
609 echo "Skipping protobuf"
658 - defer_error "You have requested use of a system copy of protobuf. This should work, but it is not recommended as it's very likely to break if you upgrade the currently installed version of protobuf."
610 + warning "You have requested use of a system copy of protobuf. This should work, but it is not recommended as it's very likely to break if you upgrade the currently installed version of protobuf."
611 return 0
612 fi
613
@@ -678,12 +630,10 @@ bundle_protobuf() {
630 run_ok "protobuf built and prepared."
631 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-protobuf"
632 else
681 - run_failed "Failed to build protobuf."
682 - defer_error_highlighted "Failed to build protobuf. You may not be able to connect this node to Netdata Cloud."
633 + run_failed "Failed to build protobuf. Netdata Cloud support will not be available in this build."
634 fi
635 else
685 - run_failed "Unable to fetch sources for protobuf."
686 - defer_error_highlighted "Unable to fetch sources for protobuf. You may not be able to connect this node to Netdata Cloud."
636 + run_failed "Unable to fetch sources for protobuf. Netdata Cloud support will not be available in this build."
637 fi
638
639 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
@@ -763,23 +713,19 @@ bundle_judy() {
713 run_ok "libJudy built and prepared."
714 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-libJudy"
715 else
766 - run_failed "Failed to build libJudy."
716 if [ -n "${NETDATA_BUILD_JUDY}" ]; then
717 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
769 -
770 - exit 1
718 + fatal "failed to build libJudy." I0003
719 else
772 - defer_error_highlighted "Failed to build libJudy. dbengine support will be disabled."
720 + run_failed "Failed to build libJudy, dbengine support will be disabled."
721 fi
722 fi
723 else
776 - run_failed "Unable to fetch sources for libJudy."
724 if [ -n "${NETDATA_BUILD_JUDY}" ]; then
725 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
779 -
780 - exit 1
726 + fatal "Unable to fetch sources for libJudy, which is required for this build of Netdata." I0004
727 else
782 - defer_error_highlighted "Unable to fetch sources for libJudy. dbengine support will be disabled."
728 + run_failed "Unable to fetch sources for libJudy, which is required for this build of Netdata."
729 fi
730 fi
731
@@ -796,12 +742,12 @@ build_jsonc() {
742 env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
743 fi
744
799 - cd "${1}" > /dev/null || exit 1
745 + cd "${1}" > /dev/null || return 1
746 # shellcheck disable=SC2086
747 run ${env_cmd} cmake -DBUILD_SHARED_LIBS=OFF .
748 # shellcheck disable=SC2086
749 run ${env_cmd} ${make} ${MAKEOPTS}
804 - cd - > /dev/null || exit 1
750 + cd - > /dev/null || return 1
751 }
752
753 copy_jsonc() {
@@ -822,7 +768,6 @@ bundle_jsonc() {
768
769 if [ -z "$(command -v cmake)" ]; then
770 run_failed "Could not find cmake, which is required to build JSON-C. The install process will continue, but Netdata Cloud support will be disabled."
825 - defer_error_highlighted "Could not find cmake, which is required to build JSON-C. The install process will continue, but Netdata Cloud support will be disabled."
771 return 0
772 fi
773
@@ -846,12 +791,10 @@ bundle_jsonc() {
791 rm -rf "${tmp}"; then
792 run_ok "JSON-C built and prepared."
793 else
849 - run_failed "Failed to build JSON-C."
850 - defer_error_highlighted "Failed to build JSON-C. Netdata Cloud support will be disabled."
794 + run_failed "Failed to build JSON-C, Netdata Cloud support will be disabled in this build."
795 fi
796 else
853 - run_failed "Unable to fetch sources for JSON-C."
854 - defer_error_highlighted "Unable to fetch sources for JSON-C. Netdata Cloud support will be disabled."
797 + run_failed "Unable to fetch sources for JSON-C, Netdata Cloud support will be disabled in this build."
798 fi
799
800 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
@@ -891,13 +834,13 @@ detect_libc() {
834 cmd=$(ldd "$ls_path" | grep -w libc | cut -d" " -f 3)
835 if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
836 echo >&2 " Detected GLIBC"
894 - libc="glibc"
895 - fi
896 - fi
837 + libc="glibc"
838 + fi
839 + fi
840 fi
841
842 if [ -z "$libc" ]; then
900 - echo >&2 " ERROR: Cannot detect a supported libc on your system!"
843 + warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
844 return 1
845 fi
846
@@ -917,11 +860,11 @@ rename_libbpf_packaging() {
860
861
862 build_libbpf() {
920 - cd "${1}/src" > /dev/null || exit 1
863 + cd "${1}/src" > /dev/null || return 1
864 mkdir root build
865 # shellcheck disable=SC2086
866 run env CFLAGS=-fPIC CXXFLAGS= LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
924 - cd - > /dev/null || exit 1
867 + cd - > /dev/null || return 1
868 }
869
870 copy_libbpf() {
@@ -975,19 +918,17 @@ bundle_libbpf() {
918 rm -rf "${tmp}"; then
919 run_ok "libbpf built and prepared."
920 else
978 - run_failed "Failed to build libbpf."
921 if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
980 - exit 1
922 + fatal "failed to build libbpf." I0005
923 else
982 - defer_error_highlighted "Failed to build libbpf. You may not be able to use eBPF plugin."
924 + run_failed "Failed to build libbpf. eBPF support will be disabled"
925 fi
926 fi
927 else
986 - run_failed "Unable to fetch sources for libbpf."
928 if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
988 - exit 1
929 + fatal "Failed to fetch sources for libbpf." I0006
930 else
990 - defer_error_highlighted "Unable to fetch sources for libbpf. You may not be able to use eBPF plugin."
931 + run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
932 fi
933 fi
934
@@ -1024,21 +965,19 @@ bundle_ebpf_co_re() {
965 rm -rf "${tmp}"; then
966 run_ok "libbpf built and prepared."
967 else
1027 - run_failed "Failed to get eBPF CO-RE files."
968 if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
1029 - exit 1
969 + fatal "Failed to get eBPF CO-RE files." I0007
970 else
1031 - defer_error_highlighted "Failed to get CO-RE. You will not be able to use eBPF plugin."
971 + run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
972 NETDATA_DISABLE_EBPF=1
973 NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
974 fi
975 fi
976 else
1037 - run_failed "Unable to fetch sources for libbpf."
977 if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
1039 - exit 1
978 + fatal "Failed to fetch eBPF CO-RE files." I0008
979 else
1041 - defer_error_highlighted "Unable to fetch sources for eBPF CO-RE. You will not be able to use eBPF plugin."
980 + run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
981 NETDATA_DISABLE_EBPF=1
982 NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
983 fi
@@ -1075,21 +1014,26 @@ echo >&2
1014 progress "Run autotools to configure the build environment"
1015
1016 if [ "$have_autotools" ]; then
1078 - run autoreconf -ivf || exit 1
1017 + if ! run autoreconf -ivf; then
1018 + fatal "Failed to prepare Netdata sources." I0009
1019 + fi
1020 fi
1021
1022 # shellcheck disable=SC2086
1082 -run ./configure \
1083 - --prefix="${NETDATA_PREFIX}/usr" \
1084 - --sysconfdir="${NETDATA_PREFIX}/etc" \
1085 - --localstatedir="${NETDATA_PREFIX}/var" \
1086 - --libexecdir="${NETDATA_PREFIX}/usr/libexec" \
1087 - --libdir="${NETDATA_PREFIX}/usr/lib" \
1088 - --with-zlib \
1089 - --with-math \
1090 - --with-user=netdata \
1091 - ${NETDATA_CONFIGURE_OPTIONS} \
1092 - CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" || exit 1
1023 +if ! run ./configure \
1024 + --prefix="${NETDATA_PREFIX}/usr" \
1025 + --sysconfdir="${NETDATA_PREFIX}/etc" \
1026 + --localstatedir="${NETDATA_PREFIX}/var" \
1027 + --libexecdir="${NETDATA_PREFIX}/usr/libexec" \
1028 + --libdir="${NETDATA_PREFIX}/usr/lib" \
1029 + --with-zlib \
1030 + --with-math \
1031 + --with-user=netdata \
1032 + ${NETDATA_CONFIGURE_OPTIONS} \
1033 + CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"; then
1034 + fatal "Failed to configure Netdata sources." I000A
1035 +fi
1036 +
1037
1038 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
1039
@@ -1107,7 +1051,9 @@ run $make clean
1051 progress "Compile netdata"
1052
1053 # shellcheck disable=SC2086
1110 -run $make ${MAKEOPTS} || exit 1
1054 +if ! run $make ${MAKEOPTS}; then
1055 + fatal "Failed to build Netdata." I000B
1056 +fi
1057
1058 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
1059
@@ -1200,7 +1146,9 @@ touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done"
1146 # -----------------------------------------------------------------------------
1147 progress "Install netdata"
1148
1203 -run $make install || exit 1
1149 +if ! run $make install; then
1150 + fatal "Failed to install Netdata." I000C
1151 +fi
1152
1153 # -----------------------------------------------------------------------------
1154 progress "Fix generated files permissions"
@@ -1308,7 +1256,9 @@ progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
1256
1257 if [ ! -d "${NETDATA_RUN_DIR}" ]; then
1258 # this is needed if NETDATA_PREFIX is not empty
1311 - run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
1259 + if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
1260 + warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
1261 + fi
1262 fi
1263
1264 # --- stock conf dir ----
@@ -1339,7 +1289,9 @@ run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
1289 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
1290 if [ ! -d "${x}" ]; then
1291 echo >&2 "Creating directory '${x}'"
1342 - run mkdir -p "${x}" || exit 1
1292 + if ! run mkdir -p "${x}"; then
1293 + warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
1294 + fi
1295 fi
1296
1297 run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
@@ -1353,7 +1305,9 @@ run chmod 755 "${NETDATA_LOG_DIR}"
1305
1306 if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
1307 echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
1356 - run mkdir -p "${NETDATA_CLAIMING_DIR}" || exit 1
1308 + if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
1309 + warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
1310 + fi
1311 fi
1312 run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
1313 run chmod 770 "${NETDATA_CLAIMING_DIR}"
@@ -1564,7 +1518,6 @@ install_go() {
1518
1519 if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
1520 run_failed "go.d plugin download failed, go.d plugin will not be available"
1567 - defer_error "go.d plugin download failed, go.d plugin will not be available"
1521 echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
1522 echo >&2
1523 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
@@ -1581,8 +1534,7 @@ install_go() {
1534 echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
1535 echo >&2
1536
1584 - run_failed "go.d.plugin package files checksum validation failed."
1585 - defer_error "go.d.plugin package files checksum validation failed, go.d.plugin will not be available"
1537 + run_failed "go.d.plugin package files checksum validation failed. go.d.plugin will not be available."
1538 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
1539 return 0
1540 fi
@@ -1608,20 +1560,21 @@ install_go
1560
1561 should_install_ebpf() {
1562 if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
1611 - run_failed "eBPF explicitly disabled."
1612 - defer_error "eBPF explicitly disabled."
1563 + run_failed "eBPF has been explicitly disabled, it will not be available in this install."
1564 return 1
1565 fi
1566
1567 if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
1617 - run_failed "Currently eBPF is only supported on Linux on X86_64."
1618 - defer_error "Currently eBPF is only supported on Linux on X86_64."
1568 + if [ "${NETDATA_DISABLE_EBPF:=1}" -eq 0 ]; then
1569 + run_failed "Currently eBPF is only supported on Linux on X86_64."
1570 + fi
1571 +
1572 return 1
1573 fi
1574
1575 # Check Kernel Config
1576 if ! run "${INSTALLER_DIR}"/packaging/check-kernel-config.sh; then
1624 - echo >&2 "Warning: Kernel unsupported or missing required config (eBPF may not work on your system)"
1577 + warning "Kernel unsupported or missing required config (eBPF may not work on your system)"
1578 fi
1579
1580 return 0
@@ -1777,7 +1730,7 @@ if [ ${DONOTSTART} -eq 1 ]; then
1730 create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1731 else
1732 if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
1780 - fatal "Cannot start netdata!"
1733 + fatal "Cannot start netdata!" I000D
1734 fi
1735
1736 started=1
packaging/installer/functions.sh
+49 -15
@@ -2,6 +2,8 @@
2
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 +# next unused error code: L0003
6 +
7 # make sure we have a UID
8 [ -z "${UID}" ] && UID="$(id -u)"
9 # -----------------------------------------------------------------------------
@@ -42,6 +44,7 @@ setup_terminal() {
44 TPUT_RESET="$(tput sgr 0)"
45 # shellcheck disable=SC2034
46 TPUT_BLACK="$(tput setaf 0)"
47 + # shellcheck disable=SC2034
48 TPUT_RED="$(tput setaf 1)"
49 TPUT_GREEN="$(tput setaf 2)"
50 # shellcheck disable=SC2034
@@ -99,7 +102,7 @@ get() {
102 elif command -v wget > /dev/null 2>&1; then
103 wget -T 15 -O - "${url}"
104 else
102 - fatal "I need curl or wget to proceed, but neither is available on this system."
105 + fatal "I need curl or wget to proceed, but neither is available on this system." "L0002"
106 fi
107 }
108
@@ -245,17 +248,43 @@ find_processors() {
248 }
249
250 # -----------------------------------------------------------------------------
251 +exit_reason() {
252 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
253 + EXIT_REASON="${1}"
254 + EXIT_CODE="${2}"
255 + if [ -n "${NETDATA_PROPAGATE_WARNINGS}" ]; then
256 + export EXIT_REASON
257 + export EXIT_CODE
258 + export NETDATA_WARNINGS="${NETDATA_WARNINGS}${SAVED_WARNINGS}"
259 + fi
260 + fi
261 +}
262 +
263 fatal() {
249 - printf >&2 "%s ABORTED %s %s \n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${*}"
264 + printf >&2 "%s ABORTED %s %s \n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1}"
265 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
266 + SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
267 + fi
268 + exit_reason "${1}" "${2}"
269 exit 1
270 }
271
272 +warning() {
273 + printf >&2 "%s WARNING %s %s\n\n" "%{TPUT_BGYELLOW}${TPUT_BLACK}${TPUT_BOLD}" "${TPUT_RESET}" "${1}"
274 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
275 + SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
276 + fi
277 +}
278 +
279 run_ok() {
254 - printf >&2 "%s OK %s %s \n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${*}"
280 + printf >&2 "%s OK %s %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1:-''}"
281 }
282
283 run_failed() {
258 - printf >&2 "%s FAILED %s %s \n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${*}"
284 + printf >&2 "%s FAILED %s %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1:-''}"
285 + if [ -n "${NETDATA_SAVE_WARNINGS}" ] && [ -n "${1:-''}" ]; then
286 + SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
287 + fi
288 }
289
290 ESCAPED_PRINT_METHOD=
@@ -299,6 +328,9 @@ run() {
328 if [ ${ret} -ne 0 ]; then
329 run_failed
330 printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
331 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
332 + SAVED_WARNINGS="${SAVED_WARNINGS}\n - Command '${*}' failed with exit code ${ret}."
333 + fi
334 else
335 run_ok
336 printf >> "${run_logfile}" "OK\n"
@@ -430,14 +462,14 @@ install_non_systemd_init() {
462 run chkconfig netdata on &&
463 return 0
464 else
433 - echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
465 + warning "Could not determine what type of init script to install on this system."
466 return 1
467 fi
468 elif [ -f /etc/init.d/netdata ]; then
469 echo >&2 "file '/etc/init.d/netdata' already exists."
470 return 0
471 else
440 - echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
472 + warning "Could not determine what type of init script to install on this system."
473 fi
474
475 return 1
@@ -507,7 +539,7 @@ install_netdata_service() {
539 ${ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED} &&
540 return 0
541 else
510 - echo >&2 "no systemd directory; cannot install netdata.service"
542 + warning "Could not find a systemd service directory, unable to install Netdata systemd service."
543 fi
544 else
545 install_non_systemd_init
@@ -559,7 +591,7 @@ stop_netdata_on_pid() {
591 printf >&2 "Stopping netdata on pid %s ..." "${pid}"
592 while [ -n "${pid}" ] && [ ${ret} -eq 0 ]; do
593 if [ ${count} -gt 24 ]; then
562 - echo >&2 "Cannot stop the running netdata on pid ${pid}."
594 + warning "Cannot stop netdata agent with PID ${pid}."
595 return 1
596 fi
597
@@ -584,7 +616,7 @@ stop_netdata_on_pid() {
616
617 echo >&2
618 if [ ${ret} -eq 0 ]; then
587 - echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
619 + warning "Failed to stop netdata agent process with PID ${pid}."
620 return 1
621 fi
622
@@ -687,7 +719,7 @@ restart_netdata() {
719
720 if [ ${started} -eq 0 ]; then
721 # still not started... another forced attempt, just run the binary
690 - echo >&2 "Netdata service still not started, attempting another forced restart by running '${netdata} ${*}'"
722 + warning "Netdata service still not started, attempting another forced restart by running '${netdata} ${*}'"
723 run stop_all_netdata
724 run "${netdata}" "${@}"
725 return $?
@@ -798,7 +830,7 @@ portable_add_user() {
830 run sysadminctl -addUser "${username}" && return 0
831 fi
832
801 - echo >&2 "Failed to add ${username} user account !"
833 + warning "Failed to add ${username} user account!"
834
835 return 1
836 }
@@ -834,7 +866,7 @@ portable_add_group() {
866 dseditgroup -o create "${groupname}" && return 0
867 fi
868
837 - echo >&2 "Failed to add ${groupname} user group !"
869 + warning >&2 "Failed to add ${groupname} user group !"
870 return 1
871 }
872
@@ -845,7 +877,8 @@ portable_add_user_to_group() {
877 # Check if group exist
878 if ! cut -d ':' -f 1 < /etc/group | grep "^${groupname}$" > /dev/null 2>&1; then
879 echo >&2 "Group '${groupname}' does not exist."
848 - return 1
880 + # Don’t treat this as a failure, if the group does not exist we should not be trying to add the user to it.
881 + return 0
882 fi
883
884 # Check if user is in group
@@ -876,7 +909,8 @@ portable_add_user_to_group() {
909 if command -v dseditgroup 1> /dev/null 2>&1; then
910 dseditgroup -u "${username}" "${groupname}" && return 0
911 fi
879 - echo >&2 "Failed to add user ${username} to group ${groupname} !"
912 +
913 + warning >&2 "Failed to add user ${username} to group ${groupname}!"
914 return 1
915 fi
916 }
@@ -889,7 +923,7 @@ safe_sha256sum() {
923 elif command -v shasum > /dev/null 2>&1; then
924 shasum -a 256 "$@"
925 else
892 - fatal "I could not find a suitable checksum binary to use"
926 + fatal "I could not find a suitable checksum binary to use" "L0001"
927 fi
928 }
929
packaging/installer/kickstart.sh
+32 -7
@@ -35,8 +35,8 @@ NETDATA_ONLY_BUILD=0
35 NETDATA_ONLY_NATIVE=0
36 NETDATA_ONLY_STATIC=0
37 NETDATA_REQUIRE_CLOUD=1
38 +NETDATA_WARNINGS=""
39 RELEASE_CHANNEL="nightly"
39 -WARNINGS=""
40
41 if [ -n "$DISABLE_TELEMETRY" ]; then
42 NETDATA_DISABLE_TELEMETRY="${DISABLE_TELEMETRY}"
@@ -343,9 +343,9 @@ cleanup() {
343 }
344
345 deferred_warnings() {
346 - if [ -n "${WARNINGS}" ]; then
346 + if [ -n "${NETDATA_WARNINGS}" ]; then
347 printf >&2 "%s\n" "The following non-fatal warnings or errors were encountered:"
348 - echo >&2 "${WARNINGS}"
348 + echo >&2 "${NETDATA_WARNINGS}"
349 printf >&2 "\n"
350 fi
351 }
@@ -418,7 +418,8 @@ run() {
418 if [ ${ret} -ne 0 ]; then
419 printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET}"
420 printf "%s\n" "FAILED with exit code ${ret}" >> "${run_logfile}"
421 - WARNINGS="${WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}."
421 + # shellcheck disable=SC2089
422 + NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}."
423 else
424 printf >&2 "%s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET}"
425 printf "OK\n" >> "${run_logfile}"
@@ -429,7 +430,7 @@ run() {
430
431 warning() {
432 printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*}"
432 - WARNINGS="${WARNINGS}\n - ${*}"
433 + NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${*}"
434 }
435
436 _cannot_use_tmpdir() {
@@ -645,11 +646,19 @@ update() {
646 return 0
647 fi
648
649 + export NETDATA_SAVE_WARNINGS=1
650 + export NETDATA_PROPAGATE_WARNINGS=1
651 + # shellcheck disable=SC2090
652 + export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
653 if run ${ROOTCMD} "${updater}" --not-running-from-cron; then
654 progress "Updated existing install at ${ndprefix}"
655 return 0
656 else
652 - fatal "Failed to update existing Netdata install at ${ndprefix}" F0100
657 + if [ -n "${EXIT_REASON}" ]; then
658 + fatal "Failed to update existing Netdata install at ${ndprefix}: ${EXIT_REASON}" "${EXIT_CODE}"
659 + else
660 + fatal "Failed to update existing Netdata install at ${ndprefix}." U0000
661 + fi
662 fi
663 else
664 warning "Could not find a usable copy of the updater script."
@@ -682,6 +691,10 @@ uninstall() {
691 return 0
692 else
693 progress "Found existing netdata-uninstaller. Running it.."
694 + export NETDATA_SAVE_WARNINGS=1
695 + export NETDATA_PROPAGATE_WARNINGS=1
696 + # shellcheck disable=SC2090
697 + export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
698 if ! run ${ROOTCMD} "${uninstaller}" $FLAGS; then
699 warning "Uninstaller failed. Some parts of Netdata may still be present on the system."
700 fi
@@ -695,6 +708,10 @@ uninstall() {
708 progress "Downloading netdata-uninstaller ..."
709 download "${uninstaller_url}" "${tmpdir}/netdata-uninstaller.sh"
710 chmod +x "${tmpdir}/netdata-uninstaller.sh"
711 + export NETDATA_SAVE_WARNINGS=1
712 + export NETDATA_PROPAGATE_WARNINGS=1
713 + # shellcheck disable=SC2090
714 + export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
715 if ! run ${ROOTCMD} "${tmpdir}/netdata-uninstaller.sh" $FLAGS; then
716 warning "Uninstaller failed. Some parts of Netdata may still be present on the system."
717 fi
@@ -1493,12 +1510,20 @@ build_and_install() {
1510 opts="${opts} --disable-cloud"
1511 fi
1512
1513 + export NETDATA_SAVE_WARNINGS=1
1514 + export NETDATA_PROPAGATE_WARNINGS=1
1515 + # shellcheck disable=SC2090
1516 + export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
1517 # shellcheck disable=SC2086
1518 run ${ROOTCMD} ./netdata-installer.sh ${opts}
1519
1520 case $? in
1521 1)
1501 - fatal "netdata-installer.sh failed to run correctly." F0007
1522 + if [ -n "${EXIT_REASON}" ]; then
1523 + fatal "netdata-installer.sh failed to run: ${EXIT_REASON}" "${EXIT_CODE}"
1524 + else
1525 + fatal "netdata-installer.sh failed to run correctly." I0000
1526 + fi
1527 ;;
1528 2)
1529 fatal "Insufficient RAM to install netdata." F0008
packaging/installer/netdata-uninstaller.sh
+63 -28
@@ -10,6 +10,8 @@
10 #
11 # Author: Paweł Krupa <paulfantom@gmail.com>
12 # Author: Pavlos Emm. Katsoulakis <paul@netdata.cloud>
13 +#
14 +# Next unused error code: R0005
15
16 usage="$(basename "$0") [-h] [-f ] -- program to calculate the answer to life, the universe and everything
17
@@ -51,17 +53,57 @@ while :; do
53 esac
54 done
55
56 +if [ -n "${script_source}" ]; then
57 + script_name="$(basename "${script_source}")"
58 +else
59 + script_name="netdata-updater.sh"
60 +fi
61 +
62 +info() {
63 + echo >&3 "$(date) : INFO: ${script_name}: " "${1}"
64 +}
65 +
66 +error() {
67 + echo >&3 "$(date) : ERROR: ${script_name}: " "${1}"
68 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
69 + NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${1}"
70 + fi
71 +}
72 +
73 +fatal() {
74 + echo >&3 "$(date) : FATAL: ${script_name}: FAILED TO UPDATE NETDATA: " "${1}"
75 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
76 + NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${1}"
77 + fi
78 + exit_reason "${1}" "${2}"
79 + exit 1
80 +}
81 +
82 +exit_reason() {
83 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
84 + EXIT_REASON="${1}"
85 + EXIT_CODE="${2}"
86 + if [ -n "${NETDATA_PROPAGATE_WARNINGS}" ]; then
87 + export EXIT_REASON
88 + export EXIT_CODE
89 + export NETDATA_WARNINGS
90 + fi
91 + fi
92 +}
93 +
94 if [ "$YES" != "1" ]; then
95 echo >&2 "This script will REMOVE netdata from your system."
96 echo >&2 "Run it again with --yes to do it."
97 + exit_reason "User did not accept uninstalling." R0001
98 exit 1
99 fi
100
101 if [ "$(id -u)" -ne 0 ]; then
61 - echo >&2 "This script SHOULD be run as root or otherwise it won't delete all installed components."
102 + error "This script SHOULD be run as root or otherwise it won't delete all installed components."
103 key="n"
104 read -r 1 -p "Do you want to continue as non-root user [y/n] ? " key
105 if [ "$key" != "y" ] && [ "$key" != "Y" ]; then
106 + exit_reason "User cancelled uninstall." R0002
107 exit 1
108 fi
109 fi
@@ -107,7 +149,7 @@ create_tmp_directory() {
149 if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
150 if _cannot_use_tmpdir /tmp; then
151 if _cannot_use_tmpdir "${PWD}"; then
110 - fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." F0400
152 + fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." R0003
153 else
154 TMPDIR="${PWD}"
155 fi
@@ -325,14 +367,6 @@ setup_terminal() {
367 }
368 setup_terminal || echo > /dev/null
369
328 -run_ok() {
329 - printf >&2 "%s OK %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
330 -}
331 -
332 -run_failed() {
333 - printf >&2 "%s FAILED %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
334 -}
335 -
370 ESCAPED_PRINT_METHOD=
371 if printf "%s " test > /dev/null 2>&1; then
372 ESCAPED_PRINT_METHOD="printfq"
@@ -373,10 +407,11 @@ run() {
407
408 ret=$?
409 if [ ${ret} -ne 0 ]; then
376 - run_failed
410 + printf >&2 "%s FAILED %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
411 printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
412 + NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}."
413 else
379 - run_ok
414 + printf >&2 "%s OK %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
415 printf >> "${run_logfile}" "OK\n"
416 fi
417
@@ -387,14 +422,14 @@ portable_del_group() {
422 groupname="${1}"
423
424 # Check if group exist
390 - echo >&2 "Removing ${groupname} user group ..."
425 + info "Removing ${groupname} user group ..."
426
427 # Linux
428 if command -v groupdel 1> /dev/null 2>&1; then
429 if grep -q "${groupname}" /etc/group; then
430 run groupdel "${groupname}" && return 0
431 else
397 - echo >&2 "Group ${groupname} already removed in a previous step."
432 + info "Group ${groupname} already removed in a previous step."
433 return 0
434 fi
435 fi
@@ -404,12 +439,12 @@ portable_del_group() {
439 if dseditgroup -o read netdata 1> /dev/null 2>&1; then
440 run dseditgroup -o delete "${groupname}" && return 0
441 else
407 - echo >&2 "Could not find group ${groupname}, nothing to do"
442 + info "Could not find group ${groupname}, nothing to do"
443 return 0
444 fi
445 fi
446
412 - echo >&2 "Group ${groupname} was not automatically removed, you might have to remove it manually"
447 + error "Group ${groupname} was not automatically removed, you might have to remove it manually"
448 return 1
449 }
450
@@ -453,7 +488,7 @@ issystemd() {
488
489 portable_del_user() {
490 username="${1}"
456 - echo >&2 "Deleting ${username} user account ..."
491 + info "Deleting ${username} user account ..."
492
493 # Linux
494 if command -v userdel 1> /dev/null 2>&1; then
@@ -465,7 +500,7 @@ portable_del_user() {
500 run sysadminctl -deleteUser "${username}" && return 0
501 fi
502
468 - echo >&2 "User ${username} could not be deleted from system, you might have to remove it manually"
503 + error "User ${username} could not be deleted from system, you might have to remove it manually"
504 return 1
505 }
506
@@ -474,7 +509,7 @@ portable_del_user_from_group() {
509 username="${2}"
510
511 # username is not in group
477 - echo >&2 "Deleting ${username} user from ${groupname} group ..."
512 + info "Deleting ${username} user from ${groupname} group ..."
513
514 # Linux
515 if command -v gpasswd 1> /dev/null 2>&1; then
@@ -496,16 +531,16 @@ portable_del_user_from_group() {
531 run dseditgroup -o delete -u "${username}" "${groupname}" && return 0
532 fi
533
499 - echo >&2 "Failed to delete user ${username} from group ${groupname} !"
534 + error "Failed to delete user ${username} from group ${groupname} !"
535 return 1
536 }
537
538 quit_msg() {
539 echo
540 if [ "$FILE_REMOVAL_STATUS" -eq 0 ]; then
506 - echo >&2 "Something went wrong :("
541 + fatal "Failed to completely remove Netdata from this system." R0004
542 else
508 - echo >&2 "Netdata files were successfully removed from your system"
543 + info "Netdata files were successfully removed from your system"
544 fi
545 }
546
@@ -513,7 +548,7 @@ rm_file() {
548 FILE="$1"
549 if [ -f "${FILE}" ]; then
550 if user_input "Do you want to delete this file '$FILE' ? "; then
516 - run rm -v "${FILE}"
551 + run rm -v "${FILE}"
552 fi
553 fi
554 }
@@ -559,10 +594,10 @@ stop_netdata_on_pid() {
594
595 pidisnetdata "${pid}" || return 0
596
562 - printf >&2 "Stopping netdata on pid %s ..." "${pid}"
597 + info "Stopping netdata on pid ${pid} ..."
598 while [ -n "$pid" ] && [ ${ret} -eq 0 ]; do
599 if [ ${count} -gt 24 ]; then
565 - echo >&2 "Cannot stop the running netdata on pid ${pid}."
600 + error "Cannot stop the running netdata on pid ${pid}."
601 return 1
602 fi
603
@@ -587,11 +622,11 @@ stop_netdata_on_pid() {
622
623 echo >&2
624 if [ ${ret} -eq 0 ]; then
590 - echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
625 + error "SORRY! CANNOT STOP netdata ON PID ${pid} !"
626 return 1
627 fi
628
594 - echo >&2 "netdata on pid ${pid} stopped."
629 + info "netdata on pid ${pid} stopped."
630 return 0
631 }
632
@@ -657,7 +692,7 @@ trap quit_msg EXIT
692 . "${ENVIRONMENT_FILE}" || exit 1
693
694 #### STOP NETDATA
660 -echo >&2 "Stopping a possibly running netdata..."
695 +info "Stopping a possibly running netdata..."
696 stop_all_netdata
697
698 #### REMOVE NETDATA FILES
packaging/installer/netdata-updater.sh
+71 -44
@@ -28,6 +28,8 @@
28 # Author: Pavlos Emm. Katsoulakis <paul@netdata.cloud>
29 # Author: Austin S. Hemmelgarn <austin@netdata.cloud>
30
31 +# Next unused error code: U001A
32 +
33 set -e
34
35 PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"
@@ -55,18 +57,37 @@ else
57 fi
58
59 info() {
58 - echo >&3 "$(date) : INFO: ${script_name}: " "${@}"
60 + echo >&3 "$(date) : INFO: ${script_name}: " "${1}"
61 }
62
63 error() {
62 - echo >&3 "$(date) : ERROR: ${script_name}: " "${@}"
64 + echo >&3 "$(date) : ERROR: ${script_name}: " "${1}"
65 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
66 + NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${1}"
67 + fi
68 }
69
70 fatal() {
66 - echo >&3 "$(date) : FATAL: ${script_name}: FAILED TO UPDATE NETDATA: " "${@}"
71 + echo >&3 "$(date) : FATAL: ${script_name}: FAILED TO UPDATE NETDATA: " "${1}"
72 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
73 + NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${1}"
74 + fi
75 + exit_reason "${1}" "${2}"
76 exit 1
77 }
78
79 +exit_reason() {
80 + if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
81 + EXIT_REASON="${1}"
82 + EXIT_CODE="${2}"
83 + if [ -n "${NETDATA_PROPAGATE_WARNINGS}" ]; then
84 + export EXIT_REASON
85 + export EXIT_CODE
86 + export NETDATA_WARNINGS
87 + fi
88 + fi
89 +}
90 +
91 issystemd() {
92 # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
93 if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then
@@ -158,8 +179,7 @@ enable_netdata_updater() {
179 updater_type="$(_get_scheduler_type)"
180 ;;
181 *)
161 - error "Unrecognized updater type ${updater_type} requested. Supported types are 'systemd', 'interval', and 'crontab'."
162 - exit 1
182 + fatal "Unrecognized updater type ${updater_type} requested. Supported types are 'systemd', 'interval', and 'crontab'." U0001
183 ;;
184 esac
185
@@ -172,8 +192,7 @@ enable_netdata_updater() {
192 info "If the update process fails, the failure will be logged to the systemd journal just like a regular service failure."
193 info "Successful updates should produce empty logs."
194 else
175 - error "Systemd-based auto-update scheduling requested, but this does not appear to be a systemd system."
176 - error "Auto-updates have NOT been enabled."
195 + error "Systemd-based auto-update scheduling requested, but this does not appear to be a systemd system. Auto-updates have NOT been enabled."
196 return 1
197 fi
198 ;;
@@ -185,8 +204,7 @@ enable_netdata_updater() {
204 info "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."
205 info "Successful updates will not send an email."
206 else
188 - error "Interval-based auto-update scheduling requested, but I could not find an interval scheduling directory."
189 - error "Auto-updates have NOT been enabled."
207 + error "Interval-based auto-update scheduling requested, but I could not find an interval scheduling directory. Auto-updates have NOT been enabled."
208 return 1
209 fi
210 ;;
@@ -200,14 +218,12 @@ enable_netdata_updater() {
218 info "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."
219 info "Successful updates will not send an email."
220 else
203 - error "Crontab-based auto-update scheduling requested, but there is no '/etc/cron.d'."
204 - error "Auto-updates have NOT been enabled."
221 + error "Crontab-based auto-update scheduling requested, but there is no '/etc/cron.d'. Auto-updates have NOT been enabled."
222 return 1
223 fi
224 ;;
225 *)
209 - error "Unable to determine what type of auto-update scheduling to use."
210 - error "Auto-updates have NOT been enabled."
226 + error "Unable to determine what type of auto-update scheduling to use. Auto-updates have NOT been enabled."
227 return 1
228 esac
229
@@ -251,7 +267,7 @@ safe_sha256sum() {
267 elif command -v shasum > /dev/null 2>&1; then
268 shasum -a 256 "$@"
269 else
254 - fatal "I could not find a suitable checksum binary to use"
270 + fatal "I could not find a suitable checksum binary to use" U0002
271 fi
272 }
273
@@ -294,7 +310,7 @@ create_tmp_directory() {
310 if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then
311 if _cannot_use_tmpdir /tmp ; then
312 if _cannot_use_tmpdir "${PWD}" ; then
297 - fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again."
313 + fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." U0003
314 else
315 TMPDIR="${PWD}"
316 fi
@@ -334,9 +350,9 @@ download() {
350 if [ ${ret} -eq 0 ]; then
351 return 0
352 elif [ ${ret} -eq 255 ]; then
337 - fatal "I need curl or wget to proceed, but neither is available on this system."
353 + fatal "I need curl or wget to proceed, but neither is available on this system." U0004
354 else
339 - fatal "Cannot download ${url}"
355 + fatal "Cannot download ${url}" U0005
356 fi
357 }
358
@@ -349,7 +365,7 @@ get_netdata_latest_tag() {
365 elif command -v wget >/dev/null 2>&1; then
366 tag=$(wget --max-redirect=0 "${url}" 2>&1 | grep Location | cut -d ' ' -f2 | grep -m 1 -o '[^/]*$')
367 else
352 - fatal "I need curl or wget to proceed, but neither of them are available on this system."
368 + fatal "I need curl or wget to proceed, but neither of them are available on this system." U0006
369 fi
370
371 echo "${tag}" >"${dest}"
@@ -440,10 +456,10 @@ get_latest_version() {
456 }
457
458 validate_environment_file() {
443 - if [ -n "${RELEASE_CHANNEL}" ] && [ -n "${NETDATA_PREFIX}" ] && [ -n "${REINSTALL_OPTIONS}" ] && [ -n "${IS_NETDATA_STATIC_BINARY}" ]; then
459 + if [ -n "${NETDATA_PREFIX+SET_BUT_NULL}" ] && [ -n "${REINSTALL_OPTIONS}" ]; then
460 return 0
461 else
446 - error "Environment file located at ${ENVIRONMENT_FILE} is not valid, unable to update."
462 + fatal "Environment file located at ${ENVIRONMENT_FILE} is not valid, unable to update." U0007
463 fi
464 }
465
@@ -513,7 +529,7 @@ update_build() {
529
530 RUN_INSTALLER=0
531 ndtmpdir=$(create_tmp_directory)
516 - cd "$ndtmpdir" || exit 1
532 + cd "$ndtmpdir" || fatal "Failed to change current working directory to ${ndtmpdir}" U0016
533
534 install_build_dependencies
535
@@ -526,12 +542,12 @@ update_build() {
542 info "Newest version is already installed"
543 else
544 if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then
529 - fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${ndtmpdir}\nUsually this is a result of an older copy of the tarball or checksum file being cached somewhere upstream and can be resolved by retrying in an hour."
545 + fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${ndtmpdir}\nUsually this is a result of an older copy of the tarball or checksum file being cached somewhere upstream and can be resolved by retrying in an hour." U0008
546 fi
547 NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2> /dev/null | cut -d' ' -f1)"
548 tar -xf netdata-latest.tar.gz >&3 2>&3
549 rm netdata-latest.tar.gz >&3 2>&3
534 - cd "$(find . -maxdepth 1 -name "netdata-${path_version}*" | head -n 1)" || exit 1
550 + cd "$(find . -maxdepth 1 -name "netdata-${path_version}*" | head -n 1)" || fatal "Failed to switch to build directory" U0017
551 RUN_INSTALLER=1
552 fi
553 fi
@@ -550,7 +566,7 @@ update_build() {
566 do_not_start="--dont-start-it"
567 fi
568
553 - env="TMPDIR='${TMPDIR}'"
569 + env="env TMPDIR=${TMPDIR}"
570
571 if [ -n "${NETDATA_SELECTED_DASHBOARD}" ]; then
572 env="${env} NETDATA_SELECTED_DASHBOARD=${NETDATA_SELECTED_DASHBOARD}"
@@ -558,7 +574,7 @@ update_build() {
574
575 if [ ! -x ./netdata-installer.sh ]; then
576 if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
561 - cd "$(find . -mindepth 1 -maxdepth 1 -type d)" || exit 1
577 + cd "$(find . -mindepth 1 -maxdepth 1 -type d)" || fatal "Failed to switch to build directory" U0018
578 fi
579 fi
580
@@ -573,7 +589,18 @@ update_build() {
589 fi
590
591 info "Re-installing netdata..."
576 - eval "${env} ./netdata-installer.sh ${REINSTALL_OPTIONS} --dont-wait ${do_not_start}" >&3 2>&3 || fatal "FAILED TO COMPILE/INSTALL NETDATA"
592 + export NETDATA_SAVE_WARNINGS=1
593 + export NETDATA_PROPAGATE_WARNINGS=1
594 + export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
595 + # shellcheck disable=SC2086
596 + if ! ${env} ./netdata-installer.sh ${REINSTALL_OPTIONS} --dont-wait ${do_not_start} >&3 2>&3; then
597 + if [ -n "${EXIT_REASON}" ]; then
598 + fatal "Failed to rebuild existing netdata install: ${EXIT_REASON}" "U${EXIT_CODE}"
599 + else
600 + fatal "Failed to rebuild existing netdata reinstall." UI0000
601 + fi
602 + fi
603 + eval "${env} ./netdata-installer.sh ${REINSTALL_OPTIONS} --dont-wait ${do_not_start}" >&3 2>&3 || fatal "FAILED TO COMPILE/INSTALL NETDATA" U0009
604
605 # We no longer store checksum info here. but leave this so that we clean up all environment files upon next update.
606 sed -i '/NETDATA_TARBALL/d' "${ENVIRONMENT_FILE}"
@@ -595,14 +622,14 @@ update_static() {
622 PREVDIR="$(pwd)"
623
624 info "Entering ${ndtmpdir}"
598 - cd "${ndtmpdir}" || exit 1
625 + cd "${ndtmpdir}" || fatal "Failed to change current working directory to ${ndtmpdir}" U0019
626
627 if update_available; then
628 sysarch="$(uname -m)"
629 download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt"
630 download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-${sysarch}-latest.gz.run"
631 if ! grep "netdata-${sysarch}-latest.gz.run" "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
605 - fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${ndtmpdir}\nUsually this is a result of an older copy of the file being cached somewhere and can be resolved by simply retrying in an hour."
632 + fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${ndtmpdir}\nUsually this is a result of an older copy of the file being cached somewhere and can be resolved by simply retrying in an hour." U000A
633 fi
634
635 if [ -e /opt/netdata/etc/netdata/.install-type ] ; then
@@ -637,7 +664,7 @@ update_binpkg() {
664 elif [ -s "/usr/lib/os-release" ] && [ -r "/usr/lib/os-release" ]; then
665 os_release_file="/usr/lib/os-release"
666 else
640 - fatal "Cannot find an os-release file ..." F0401
667 + fatal "Cannot find an os-release file ..." U000B
668 fi
669
670 # shellcheck disable=SC1090
@@ -733,20 +760,20 @@ update_binpkg() {
760
761 if [ -n "${repo_subcmd}" ]; then
762 # shellcheck disable=SC2086
736 - env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} || fatal "Failed to update repository metadata."
763 + env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} || fatal "Failed to update repository metadata." U000C
764 fi
765
766 for repopkg in netdata-repo netdata-repo-edge; do
767 if ${pkg_installed_check} ${repopkg} > /dev/null 2>&1; then
768 # shellcheck disable=SC2086
742 - env ${env} ${pm_cmd} ${upgrade_cmd} ${pkg_install_opts} ${repopkg} || fatal "Failed to update Netdata repository config."
769 + env ${env} ${pm_cmd} ${upgrade_cmd} ${pkg_install_opts} ${repopkg} || fatal "Failed to update Netdata repository config." U000D
770 # shellcheck disable=SC2086
744 - env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} || fatal "Failed to update repository metadata."
771 + env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} || fatal "Failed to update repository metadata." U000E
772 fi
773 done
774
775 # shellcheck disable=SC2086
749 - env ${env} ${pm_cmd} ${upgrade_cmd} ${pkg_install_opts} netdata || fatal "Failed to update Netdata package."
776 + env ${env} ${pm_cmd} ${upgrade_cmd} ${pkg_install_opts} netdata || fatal "Failed to update Netdata package." U000F
777 }
778
779 # Simple function to encapsulate original updater behavior.
@@ -793,19 +820,19 @@ if [ "${ENVIRONMENT_FILE}" = "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; th
820 elif [ -r "${itpath}" ]; then
821 ENVIRONMENT_FILE="$(dirname "${itpath}")/.environment"
822 else
796 - fatal "Cannot find environment file or install type file, unable to update."
823 + fatal "Cannot find environment file or install type file, unable to update." U0010
824 fi
825 fi
826 fi
827
828 if [ -r "${ENVIRONMENT_FILE}" ] ; then
829 # shellcheck source=/dev/null
803 - . "${ENVIRONMENT_FILE}" || exit 1
830 + . "${ENVIRONMENT_FILE}" || fatal "Failed to source ${ENVIRONMENT_FILE}" U0014
831 fi
832
833 if [ -r "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
834 # shellcheck source=/dev/null
808 - . "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || exit 1
835 + . "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || fatal "Failed to source $(dirname "${ENVIRONMENT_FILE}")/.install-type" U0015
836 fi
837
838 while [ -n "${1}" ]; do
@@ -854,7 +881,7 @@ export NETDATA_LIB_DIR="${NETDATA_LIB_DIR:-${NETDATA_PREFIX}/var/lib/netdata}"
881 export NETDATA_NIGHTLIES_BASEURL="${NETDATA_NIGHTLIES_BASEURL:-https://storage.googleapis.com/netdata-nightlies}"
882
883 if echo "$INSTALL_TYPE" | grep -qv ^binpkg && [ "${INSTALL_UID}" != "$(id -u)" ]; then
857 - fatal "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)"
884 + fatal "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)" U0011
885 fi
886
887 self_update
@@ -862,12 +889,12 @@ self_update
889 # shellcheck disable=SC2153
890 case "${INSTALL_TYPE}" in
891 *-build)
865 - validate_environment_file || exit 1
892 + validate_environment_file
893 set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
894 update_build && exit 0
895 ;;
896 *-static*)
870 - validate_environment_file || exit 1
897 + validate_environment_file
898 set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
899 update_static && exit 0
900 ;;
@@ -875,22 +902,22 @@ case "${INSTALL_TYPE}" in
902 update_binpkg && exit 0
903 ;;
904 "") # Fallback case for no `.install-type` file. This just works like the old install type detection.
878 - validate_environment_file || exit 1
905 + validate_environment_file
906 update_legacy
907 ;;
908 custom)
909 # At this point, we _should_ have a valid `.environment` file, but it's best to just check.
910 # If we do, then behave like the legacy updater.
884 - if validate_environment_file; then
911 + if validate_environment_file && [ -n "${IS_NETDATA_STATIC_BINARY}" ]; then
912 update_legacy
913 else
887 - fatal "This script does not support updating custom installations without valid environment files."
914 + fatal "This script does not support updating custom installations without valid environment files." U0012
915 fi
916 ;;
917 oci)
891 - fatal "This script does not support updating Netdata inside our official Docker containers, please instead update the container itself."
918 + fatal "This script does not support updating Netdata inside our official Docker containers, please instead update the container itself." U0013
919 ;;
920 *)
894 - fatal "Unrecognized installation type (${INSTALL_TYPE}), unable to update."
921 + fatal "Unrecognized installation type (${INSTALL_TYPE}), unable to update." U0014
922 ;;
923 esac