X-Git-Url: https://arthur.barton.de/gitweb/?p=netdata.git;a=blobdiff_plain;f=netdata-installer.sh;h=f926f14f2809ed7610673729ece7dd2fc8cdf973;hp=f8a7deea7f27146c2c7b72894e4ee24df3ae9da1;hb=32e8eda4c4d6370e96233a69cab861b2ebb5cc9a;hpb=4f9e8196a99a0ef01593e76cad274bf40bb46d52 diff --git a/netdata-installer.sh b/netdata-installer.sh index f8a7deea..f926f14f 100755 --- a/netdata-installer.sh +++ b/netdata-installer.sh @@ -49,7 +49,7 @@ umask 002 # Be nice on production environments renice 19 $$ >/dev/null 2>/dev/null -processors=$(grep ^processor /dev/null | wc -l) +processors=$(cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l) [ $(( processors )) -lt 1 ] && processors=1 # you can set CFLAGS before running installer @@ -73,6 +73,7 @@ DONOTSTART=0 DONOTWAIT=0 NETDATA_PREFIX= LIBS_ARE_HERE=0 +NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}" usage() { netdata_banner "installer command line options" @@ -84,7 +85,7 @@ Valid are: --install /PATH/TO/INSTALL - If your give: --install /opt + If you give: --install /opt netdata will be installed in /opt/netdata --dont-start-it @@ -97,6 +98,24 @@ Valid are: Do not wait for the user to press ENTER. Start immediately building it. + --enable-plugin-freeipmi + --disable-plugin-freeipmi + + Enable/disable the FreeIPMI plugin. + Default: enable it when libipmimonitoring is available. + + --enable-plugin-nfacct + --disable-plugin-nfacct + + Enable/disable the nfacct plugin. + Default: enable it when libmnl and libnetfilter_acct are available. + + --enable-lto + --disable-lto + + Enable/disable Link-Time-Optimization + Default: enabled + --zlib-is-really-here --libs-are-really-here @@ -124,7 +143,7 @@ For the plugins, you will at least need: USAGE } -md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null)" +md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)" get_git_config_signatures() { local x s file md5 @@ -140,7 +159,7 @@ get_git_config_signatures() { for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2) do git checkout ${c} "conf.d/${x}" || continue - s="$(cat "conf.d/${x}" | md5sum | cut -d ' ' -f 1)" + s="$(cat "conf.d/${x}" | ${md5sum} | cut -d ' ' -f 1)" echo >>configs.signatures.tmp "${s}:${x}" echo " ${s}" done @@ -184,6 +203,30 @@ do then DONOTWAIT=1 shift 1 + elif [ "$1" = "--enable-plugin-freeipmi" ] + then + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-freeipmi" + shift 1 + elif [ "$1" = "--disable-plugin-freeipmi" ] + then + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-plugin-freeipmi" + shift 1 + elif [ "$1" = "--enable-plugin-nfacct" ] + then + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-nfacct" + shift 1 + elif [ "$1" = "--disable-plugin-nfacct" ] + then + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-plugin-nfacct" + shift 1 + elif [ "$1" = "--enable-lto" ] + then + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-lto" + shift 1 + elif [ "$1" = "--disable-lto" ] + then + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-lto" + shift 1 elif [ "$1" = "--help" -o "$1" = "-h" ] then usage @@ -202,25 +245,32 @@ do done netdata_banner "real-time performance monitoring, done right!" -cat <&2 -ep \$'\001${COLOR_BOLD}${COLOR_GREEN}\002Press ENTER to build and install netdata to \'\001${COLOR_CYAN}\002${NETDATA_PREFIX}\001${COLOR_YELLOW}\002\'\001${COLOR_RESET}\002 > ' -e -r REPLY" + eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to \'\001${TPUT_CYAN}\002${NETDATA_PREFIX}\001${TPUT_YELLOW}\002\'\001${TPUT_RESET}\002 > ' -e -r REPLY" else - eval "read >&2 -ep \$'\001${COLOR_BOLD}${COLOR_GREEN}\002Press ENTER to build and install netdata to your system\001${COLOR_RESET}\002 > ' -e -r REPLY" + eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to your system\001${TPUT_RESET}\002 > ' -e -r REPLY" fi fi @@ -395,7 +445,10 @@ run ./configure \ --prefix="${NETDATA_PREFIX}/usr" \ --sysconfdir="${NETDATA_PREFIX}/etc" \ --localstatedir="${NETDATA_PREFIX}/var" \ - --with-zlib --with-math --with-user=netdata \ + --with-zlib \ + --with-math \ + --with-user=netdata \ + ${NETDATA_CONFIGURE_OPTIONS} \ CFLAGS="${CFLAGS}" || exit 1 # remove the build_error hook @@ -468,6 +521,24 @@ then fi fi +config_signature_matches() { + local md5="${1}" file="${2}" + + if [ "${BASH_VERSINFO[0]}" -ge "4" ] + then + [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0 + return 1 + fi + + if [ -f "configs.signatures" ] + then + grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null + return $? + fi + + return 1 +} + # backup user configurations installer_backup_suffix="${PID}.${RANDOM}" for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f) @@ -480,7 +551,8 @@ do if [ -z "${md5sum}" -o ! -x "${md5sum}" ] then # we don't have md5sum - keep it - cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}" + 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}" else # find it relative filename f="${x/*\/etc\/netdata\//}" @@ -494,20 +566,14 @@ do cp "conf.d/${f}" "${x}.orig" fi - if [ "${BASH_VERSINFO[0]}" -ge "4" ] - then - if [ "${configs_signatures[${md5}]}" = "${f}" ] + if config_signature_matches "${md5}" "${f}" then - # it is a stock version - don't keep it - echo >&2 "File '${x}' is stock version." - else - # edited by user - keep it - echo >&2 "File '${x}' has been edited by user." - cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}" - fi + # it is a stock version - don't keep it + echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version." else - echo >&2 "File '${x}' cannot be check for custom edits." - cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}" + # 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}" fi fi @@ -525,14 +591,14 @@ run make install || exit 1 # ----------------------------------------------------------------------------- -progress "Restore netdata configuration files" +progress "Restore user edited netdata configuration files" for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f) do if [ -f "${x}.installer_backup.${installer_backup_suffix}" ] then - cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" - rm -f "${x}.installer_backup.${installer_backup_suffix}" + run cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \ + run rm -f "${x}.installer_backup.${installer_backup_suffix}" fi done @@ -551,6 +617,7 @@ 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 @@ -560,9 +627,12 @@ if [ ${UID} -eq 0 ] 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 - # ----------------------------------------------------------------------------- progress "Install logrotate configuration for netdata" @@ -692,7 +762,13 @@ run chmod 755 "${NETDATA_LOG_DIR}" if [ ${UID} -eq 0 ] then - run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}" + # find the admin group + admin_group= + test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root" + test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon" + test -z "${admin_group}" && admin_group="${NETDATA_USER}" + + run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}" run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata" run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \; run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \; @@ -713,7 +789,7 @@ if [ ${UID} -eq 0 ] # if we managed to setcap # but we fail to execute apps.plugin # trigger setuid to root - "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1 + "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1 setcap_ret=$? fi fi @@ -724,6 +800,13 @@ if [ ${UID} -eq 0 ] run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" fi + + if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ] + then + run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" + run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" + fi + else run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}" run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata" @@ -858,7 +941,7 @@ stop_all_netdata() { myns="$(readlink /proc/self/ns/pid 2>/dev/null)" - echo >&2 "Stopping a (possibly) running netdata..." + # 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) \ @@ -974,15 +1057,15 @@ progress "Check KSM (kernel memory deduper)" ksm_is_available_but_disabled() { cat </sys/kernel/mm/ksm/run${COLOR_RESET}") - $(printf "${COLOR_YELLOW}${COLOR_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${COLOR_RESET}") + ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET} + ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET} If you enable it, you will save 40-60% of netdata memory. @@ -992,7 +1075,7 @@ KSM1 ksm_is_not_available() { cat < /dev/null +if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NSD}" = "1" ] + then + echo + echo "You may also want to remove the netdata user from the nsd group" + echo "by running:" + echo " gpasswd -d netdata nsd" +fi + UNINSTALL chmod 750 netdata-uninstaller.sh @@ -1206,22 +1298,22 @@ progress "Basic netdata instructions" cat <&2 -e "Uninstall script generated: ${COLOR_YELLOW}${COLOR_BOLD}./netdata-uninstaller.sh${COLOR_RESET}" +echo >&2 "Uninstall script generated: ${TPUT_RED}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}" if [ -d .git ] then @@ -1233,6 +1325,7 @@ force=0 export PATH="\${PATH}:${PATH}" export CFLAGS="${CFLAGS}" +export NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}" INSTALL_UID="${UID}" if [ "\${INSTALL_UID}" != "\${UID}" ] @@ -1337,7 +1430,16 @@ update && exit 0 REINSTALL chmod 755 netdata-updater.sh.new mv -f netdata-updater.sh.new netdata-updater.sh - echo >&2 -e "Update script generated : ${COLOR_YELLOW}${COLOR_BOLD}./netdata-updater.sh${COLOR_RESET}" + 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}" + if [ "${UID}" -eq 0 -a -d "/etc/cron.daily" -a ! -f "/etc/cron.daily/netdata-updater.sh" ] + 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}" + fi elif [ -f "netdata-updater.sh" ] then rm "netdata-updater.sh"