From a133c9c3b637b1dbe7b5b053f7e2572c1950cead Mon Sep 17 00:00:00 2001 From: Lennart Weller Date: Thu, 27 Jul 2017 11:55:47 +0200 Subject: New upstream version 1.7.0+dfsg --- netdata-installer.sh | 356 ++++++++++++++++----------------------------------- 1 file changed, 112 insertions(+), 244 deletions(-) (limited to 'netdata-installer.sh') diff --git a/netdata-installer.sh b/netdata-installer.sh index 6b672a242..35cb850fb 100755 --- a/netdata-installer.sh +++ b/netdata-installer.sh @@ -7,7 +7,7 @@ installer_dir="$(dirname "${0}")" if [ "${netdata_source_dir}" != "${installer_dir}" -a "${installer_dir}" != "." ] then - echo >&2 "Warninng: you are currently in '${netdata_source_dir}' but the installer is in '${installer_dir}'." + echo >&2 "Warning: you are currently in '${netdata_source_dir}' but the installer is in '${installer_dir}'." fi @@ -43,7 +43,7 @@ then export ACLOCAL_PATH fi -LC_ALL=C +export LC_ALL=C umask 002 # Be nice on production environments @@ -65,12 +65,16 @@ printf "\n" >>netdata-installer.log REINSTALL_PWD="${PWD}" REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")" +# remove options that shown not be inherited by netdata-updater.sh +REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-wait/}" +REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-start-it/}" setcap="$(which setcap 2>/dev/null || command -v setcap 2>/dev/null)" ME="$0" DONOTSTART=0 DONOTWAIT=0 +AUTOUPDATE=0 NETDATA_PREFIX= LIBS_ARE_HERE=0 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}" @@ -98,6 +102,12 @@ Valid are: Do not wait for the user to press ENTER. Start immediately building it. + --auto-update | -u + + Install netdata-updater to cron, + to update netdata automatically once per day + (can only be done for installations from git) + --enable-plugin-freeipmi --disable-plugin-freeipmi @@ -138,7 +148,7 @@ these packages installed: For the plugins, you will at least need: - curl nodejs + curl, bash v4+, python v2 or v3, node.js USAGE } @@ -203,6 +213,10 @@ do then DONOTWAIT=1 shift 1 + elif [ "$1" = "--auto-update" -o "$1" = "-u" ] + then + AUTOUPDATE=1 + shift 1 elif [ "$1" = "--enable-plugin-freeipmi" ] then NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-freeipmi" @@ -541,7 +555,7 @@ config_signature_matches() { # backup user configurations installer_backup_suffix="${PID}.${RANDOM}" -for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f) +for x in $(find -L "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f) do if [ -f "${x}" ] then @@ -552,7 +566,7 @@ do then # we don't have md5sum - keep it echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it." - run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}" + run cp -a "${x}" "${x}.installer_backup.${installer_backup_suffix}" else # find it relative filename f="${x/*\/etc\/netdata\//}" @@ -573,7 +587,7 @@ do else # edited by user - keep it echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it." - run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}" + run cp -a "${x}" "${x}.installer_backup.${installer_backup_suffix}" fi fi @@ -593,11 +607,11 @@ run make install || exit 1 # ----------------------------------------------------------------------------- progress "Restore user edited netdata configuration files" -for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f) +for x in $(find -L "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f) do if [ -f "${x}.installer_backup.${installer_backup_suffix}" ] then - run cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \ + run cp -a "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \ run rm -f "${x}.installer_backup.${installer_backup_suffix}" fi done @@ -612,42 +626,13 @@ run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name # ----------------------------------------------------------------------------- progress "Add user netdata to required user groups" -NETDATA_ADDED_TO_DOCKER=0 -NETDATA_ADDED_TO_NGINX=0 -NETDATA_ADDED_TO_VARNISH=0 -NETDATA_ADDED_TO_HAPROXY=0 -NETDATA_ADDED_TO_ADM=0 -NETDATA_ADDED_TO_NSD=0 -if [ ${UID} -eq 0 ] - then - portable_add_group netdata - portable_add_user netdata - portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1 - portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1 - portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1 - portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1 - portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1 - portable_add_user_to_group nsd netdata && NETDATA_ADDED_TO_NSD=1 - run_ok -else - run_failed "The installer does not run as root." -fi +add_netdata_user_and_group || run_failed "The installer does not run as root." + # ----------------------------------------------------------------------------- progress "Install logrotate configuration for netdata" -if [ ${UID} -eq 0 ] - then - if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ] - then - run cp system/netdata.logrotate /etc/logrotate.d/netdata - fi - - if [ -f /etc/logrotate.d/netdata ] - then - run chmod 644 /etc/logrotate.d/netdata - fi -fi +install_netdata_logrotate # ----------------------------------------------------------------------------- @@ -659,51 +644,41 @@ progress "Read installation options from netdata.conf" # function to extract values from the config file config_option() { - local key="${1}" value="${2}" line= + local section="${1}" key="${2}" value="${3}" if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] then - line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )" - [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )" + "${NETDATA_PREFIX}/usr/sbin/netdata" \ + -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \ + -W get "${section}" "${key}" "${value}" || \ + echo "${value}" + else + echo "${value}" fi - - echo "${value}" } # the user netdata will run as if [ "${UID}" = "0" ] then - NETDATA_USER="$( config_option "run as user" "netdata" )" + NETDATA_USER="$( config_option "global" "run as user" "netdata" )" else NETDATA_USER="${USER}" fi # the owners of the web files -NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )" -NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )" - -# debug flags -NETDATA_DEBUG="$( config_option "debug flags" 0 )" +NETDATA_WEB_USER="$( config_option "web" "web files owner" "${NETDATA_USER}" )" +NETDATA_WEB_GROUP="$( config_option "web" "web files group" "${NETDATA_WEB_USER}" )" # port defport=19999 -NETDATA_PORT="$( config_option "default port" ${defport} )" -NETDATA_PORT2="$( config_option "port" ${defport} )" - -if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ] -then - if [ "${NETDATA_PORT2}" != "${defport}" ] - then - NETDATA_PORT="${NETDATA_PORT2}" - fi -fi +NETDATA_PORT="$( config_option "web" "default port" ${defport} )" # directories -NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )" -NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )" -NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )" -NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )" -NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )" +NETDATA_LIB_DIR="$( config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )" +NETDATA_CACHE_DIR="$( config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )" +NETDATA_WEB_DIR="$( config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )" +NETDATA_LOG_DIR="$( config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata" )" +NETDATA_CONF_DIR="$( config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata" )" NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run" @@ -824,139 +799,14 @@ fi # ----------------------------------------------------------------------------- progress "Install netdata at system init" -installed_init_d=0 -install_non_systemd_init() { - [ "${UID}" != 0 ] && return 1 - - local key="unknown" - if [ -f /etc/os-release ] - then - source /etc/os-release || return 1 - key="${ID}-${VERSION_ID}" - - elif [ -f /etc/centos-release ] - then - key=$(&2 "Installing systemd service..." - run cp system/netdata.service /etc/systemd/system/netdata.service && \ - run systemctl daemon-reload && \ - run systemctl enable netdata - fi - else - install_non_systemd_init - fi -fi +NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata" +install_netdata_service || run_failed "Cannot install netdata init service." # ----------------------------------------------------------------------------- # check if we can re-start netdata started=0 - -isnetdata() { - if [ -d /proc/self ] - then - [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1 - [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0 - return 1 - fi - return 0 -} - -stop_netdata_on_pid() { - local pid="${1}" ret=0 count=0 - - isnetdata ${pid} || return 0 - - printf >&2 "Stopping netdata on pid ${pid} ..." - while [ ! -z "$pid" -a ${ret} -eq 0 ] - do - if [ ${count} -gt 45 ] - then - echo >&2 "Cannot stop the running netdata on pid ${pid}." - return 1 - fi - - count=$(( count + 1 )) - - run kill ${pid} 2>/dev/null - ret=$? - - test ${ret} -eq 0 && printf >&2 "." && sleep 2 - done - - echo >&2 - if [ ${ret} -eq 0 ] - then - echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !" - return 1 - fi - - echo >&2 "netdata on pid ${pid} stopped." - return 0 -} - -stop_all_netdata() { - local p myns ns - - myns="$(readlink /proc/self/ns/pid 2>/dev/null)" - - # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..." - - for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \ - $(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)" - - if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ] - then - stop_netdata_on_pid ${p} - fi - done -} - if [ ${DONOTSTART} -eq 1 ] then if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] @@ -971,40 +821,19 @@ if [ ${DONOTSTART} -eq 1 ] fi else - - progress "Start netdata" - - if [ "${UID}" -eq 0 ] + restart_netdata ${NETDATA_PREFIX}/usr/sbin/netdata "${@}" + if [ $? -ne 0 ] then - service netdata stop - stop_all_netdata - service netdata restart && started=1 - if [ ${started} -eq 0 ] - then - service netdata start && started=1 - fi - fi - - if [ ${started} -eq 0 ] - then - # still not started... - - stop_all_netdata - - echo >&2 "Starting netdata..." - run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}" - if [ $? -ne 0 ] - then - echo >&2 - echo >&2 "SORRY! FAILED TO START NETDATA!" - exit 1 - else - echo >&2 "OK. NetData Started!" - fi - echo >&2 + echo >&2 "SORRY! FAILED TO START NETDATA!" + echo >&2 + exit 1 fi + started=1 + echo >&2 "OK. NetData Started!" + echo >&2 + # ----------------------------------------------------------------------------- # save a config file, if it is not already there @@ -1289,6 +1118,23 @@ if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NSD}" = "1" ] echo " gpasswd -d netdata nsd" fi +getent group proxy > /dev/null +if [ $? -eq 0 -a "${NETDATA_ADDED_TO_PROXY}" = "1" ] + then + echo + echo "You may also want to remove the netdata user from the proxy group" + echo "by running:" + echo " gpasswd -d netdata proxy" +fi + +getent group squid > /dev/null +if [ $? -eq 0 -a "${NETDATA_ADDED_TO_SQUID}" = "1" ] + then + echo + echo "You may also want to remove the netdata user from the squid group" + echo "by running:" + echo " gpasswd -d netdata squid" +fi UNINSTALL chmod 750 netdata-uninstaller.sh @@ -1303,13 +1149,13 @@ so you can access it with: ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET} -To stop netdata, just kill it, with: +To stop netdata run: - ${TPUT_YELLOW}${TPUT_BOLD}killall netdata${TPUT_RESET} + ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET} -To start it, just run it: +To start netdata run: - ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET} + ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET} END @@ -1327,6 +1173,8 @@ export PATH="\${PATH}:${PATH}" export CFLAGS="${CFLAGS}" export NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}" +# make sure we have a UID +[ -z "\${UID}" ] && UID="\$(id -u)" INSTALL_UID="${UID}" if [ "\${INSTALL_UID}" != "\${UID}" ] then @@ -1384,10 +1232,7 @@ failed() { } get_latest_commit_id() { - git log -1 2>&3 |\\ - grep ^commit 2>&3 |\\ - head -n 1 2>&3 |\\ - cut -d ' ' -f 2 2>&3 + git rev-parse HEAD 2>&3 } update() { @@ -1417,7 +1262,7 @@ update() { emptyline info "Re-installing netdata..." - ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA" + ${REINSTALL_COMMAND} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA" [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp= return 0 @@ -1433,24 +1278,47 @@ REINSTALL echo >&2 "Update script generated : ${TPUT_GREEN}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}" echo >&2 echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} can work from cron. It will trigger an email from cron" - echo >&2 "only if it fails (it does not print anything if it can update netdata).${TPUT_RESET}" + echo >&2 "only if it fails (it does not print anything when it can update netdata).${TPUT_RESET}" if [ "${UID}" -eq "0" ] then - if [ -d "/etc/cron.daily" -a ! -f "/etc/cron.daily/netdata-updater.sh" ] + crondir= + [ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily" + [ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily" + + if [ ! -z "${crondir}" ] + then + if [ -f "${crondir}/netdata-updater.sh" -a ! -f "${crondir}/netdata-updater" ] then - echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}" - echo >&2 - echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}ln -s ${PWD}/netdata-updater.sh /etc/cron.daily/netdata-updater.sh${TPUT_RESET}" - elif [ -d "/etc/periodic/daily" -a ! -f "/etc/periodic/daily/netdata-updater" ] + # remove .sh from the filename under cron + progress "Fixing netdata-updater filename at cron" + mv -f "${crondir}/netdata-updater.sh" "${crondir}/netdata-updater" + fi + + if [ ! -f "${crondir}/netdata-updater" ] then - echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}" - echo >&2 - echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}ln -s ${PWD}/netdata-updater.sh /etc/periodic/daily/netdata-updater${TPUT_RESET}" + if [ "${AUTOUPDATE}" = "1" ] + then + progress "Installing netdata-updater at cron" + run ln -s "${PWD}/netdata-updater.sh" "${crondir}/netdata-updater" + else + echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}" + echo >&2 + echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}sudo ln -s ${PWD}/netdata-updater.sh ${crondir}/netdata-updater${TPUT_RESET}" + fi + else + progress "Refreshing netdata-updater at cron" + run rm "${crondir}/netdata-updater" + run ln -s "${PWD}/netdata-updater.sh" "${crondir}/netdata-updater" + fi + else + [ "${AUTOUPDATE}" = "1" ] && echo >&2 "Cannot figure out the cron directory to install netdata-updater." fi + else + [ "${AUTOUPDATE}" = "1" ] && echo >&2 "You need to run the installer as root for auto-updating via cron." fi -elif [ -f "netdata-updater.sh" ] - then - rm "netdata-updater.sh" +else + [ -f "netdata-updater.sh" ] && rm "netdata-updater.sh" + [ "${AUTOUPDATE}" = "1" ] && echo >&2 "Your installation method does not support daily auto-updating via cron." fi # ----------------------------------------------------------------------------- -- cgit v1.2.3