3 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
5 netdata_source_dir="$(pwd)"
6 installer_dir="$(dirname "${0}")"
8 if [ "${netdata_source_dir}" != "${installer_dir}" -a "${installer_dir}" != "." ]
10 echo >&2 "Warninng: you are currently in '${netdata_source_dir}' but the installer is in '${installer_dir}'."
14 # -----------------------------------------------------------------------------
15 # reload the user profile
17 [ -f /etc/profile ] && . /etc/profile
19 # make sure /etc/profile does not change our current directory
20 cd "${netdata_source_dir}" || exit 1
23 # -----------------------------------------------------------------------------
24 # load the required functions
26 if [ -f "${installer_dir}/installer/functions.sh" ]
28 source "${installer_dir}/installer/functions.sh" || exit 1
30 source "${netdata_source_dir}/installer/functions.sh" || exit 1
33 # make sure we save all commands we run
34 run_logfile="netdata-installer.log"
37 # -----------------------------------------------------------------------------
38 # fix PKG_CHECK_MODULES error
40 if [ -d /usr/share/aclocal ]
42 ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
49 # Be nice on production environments
50 renice 19 $$ >/dev/null 2>/dev/null
52 processors=$(cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l)
53 [ $(( processors )) -lt 1 ] && processors=1
55 # you can set CFLAGS before running installer
56 CFLAGS="${CFLAGS--O2}"
57 [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
59 # keep a log of this command
60 printf "\n# " >>netdata-installer.log
61 date >>netdata-installer.log
62 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
63 printf "%q " "$0" "${@}" >>netdata-installer.log
64 printf "\n" >>netdata-installer.log
66 REINSTALL_PWD="${PWD}"
67 REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
69 setcap="$(which setcap 2>/dev/null || command -v setcap 2>/dev/null)"
76 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
79 netdata_banner "installer command line options"
82 ${ME} <installer options>
84 Valid <installer options> are:
86 --install /PATH/TO/INSTALL
88 If you give: --install /opt
89 netdata will be installed in /opt/netdata
93 Do not (re)start netdata.
98 Do not wait for the user to press ENTER.
99 Start immediately building it.
101 --enable-plugin-freeipmi
102 --disable-plugin-freeipmi
104 Enable/disable the FreeIPMI plugin.
105 Default: enable it when libipmimonitoring is available.
107 --enable-plugin-nfacct
108 --disable-plugin-nfacct
110 Enable/disable the nfacct plugin.
111 Default: enable it when libmnl and libnetfilter_acct are available.
116 Enable/disable Link-Time-Optimization
119 --zlib-is-really-here
120 --libs-are-really-here
122 If you get errors about missing zlib,
123 or libuuid but you know it is available,
124 you have a broken pkg-config.
125 Use this option to allow it continue
126 without checking pkg-config.
128 Netdata will by default be compiled with gcc optimization -O2
129 If you need to pass different CFLAGS, use something like this:
131 CFLAGS="<gcc options>" ${ME} <installer options>
133 For the installer to complete successfully, you will need
134 these packages installed:
136 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
137 uuid-dev (or libuuid-devel)
139 For the plugins, you will at least need:
146 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
147 get_git_config_signatures() {
150 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
151 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
153 echo >configs.signatures.tmp
155 for x in $(find conf.d -name \*.conf)
159 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
161 git checkout ${c} "conf.d/${x}" || continue
162 s="$(cat "conf.d/${x}" | ${md5sum} | cut -d ' ' -f 1)"
163 echo >>configs.signatures.tmp "${s}:${x}"
166 git checkout HEAD "conf.d/${x}" || break
169 cat configs.signatures.tmp |\
173 echo "declare -A configs_signatures=("
177 echo " ['${md5}']='${file}'"
180 } >configs.signatures
182 rm configs.signatures.tmp
188 while [ ! -z "${1}" ]
190 if [ "$1" = "--install" ]
192 NETDATA_PREFIX="${2}/netdata"
194 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
198 elif [ "$1" = "--dont-start-it" ]
202 elif [ "$1" = "--dont-wait" ]
206 elif [ "$1" = "--enable-plugin-freeipmi" ]
208 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-freeipmi"
210 elif [ "$1" = "--disable-plugin-freeipmi" ]
212 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-plugin-freeipmi"
214 elif [ "$1" = "--enable-plugin-nfacct" ]
216 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-nfacct"
218 elif [ "$1" = "--disable-plugin-nfacct" ]
220 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-plugin-nfacct"
222 elif [ "$1" = "--enable-lto" ]
224 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-lto"
226 elif [ "$1" = "--disable-lto" ]
228 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-lto"
230 elif [ "$1" = "--help" -o "$1" = "-h" ]
234 elif [ "$1" = "get_git_config_signatures" ]
236 get_git_config_signatures && exit 0
241 echo >&2 "I cannot understand option '$1'."
247 netdata_banner "real-time performance monitoring, done right!"
250 You are about to build and install netdata to your system.
252 It will be installed at these locations:
254 - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
255 - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
256 - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
257 - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
258 - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
259 - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
260 - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
263 [ "${UID}" -eq 0 ] && cat <<BANNER2
264 - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
265 - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
270 This installer allows you to change the installation path.
271 Press Control-C and run the same command with --help for help.
275 if [ "${UID}" -ne 0 ]
277 if [ -z "${NETDATA_PREFIX}" ]
279 netdata_banner "wrong command line options!"
280 cat <<NONROOTNOPREFIX
282 ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
284 You are attempting to install netdata as non-root, but you plan
285 to install it in system paths.
287 Please set an installation prefix, like this:
289 $0 ${@} --install /tmp
291 or, run the installer as root:
295 We suggest to install it as root, or certain data collectors will
296 not be able to work. Netdata drops root privileges when running.
297 So, if you plan to keep it, install it as root to get the full
306 ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
307 You are about to install netdata as a non-root user.
308 Netdata will work, but a few data collection modules that
309 require root access will fail.
311 If you installing netdata permanently on your system, run
312 the installer like this:
314 ${TPUT_YELLOW}${TPUT_BOLD}sudo $0 ${@}${TPUT_RESET}
321 if [ "$(type autoreconf 2> /dev/null)" ]
329 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
330 eval $maj=\$1 $min=\$2
332 autoconf_maj_min AMAJ AMIN
337 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
341 echo "Found autotools $AMAJ.$AMIN"
344 echo "No autotools found"
347 if [ ! "$have_autotools" ]
351 echo "Will skip autoreconf step"
353 netdata_banner "autotools v2.60 required"
356 -------------------------------------------------------------------------------
357 autotools 2.60 or later is required
359 Sorry, you do not seem to have autotools 2.60 or later, which is
360 required to build from the git sources of netdata.
362 You can either install a suitable version of autotools and automake
363 or download a netdata package which does not have these dependencies.
365 Source packages where autotools have already been run are available
367 https://firehol.org/download/netdata/
369 The unsigned/master folder tracks the head of the git tree and released
370 packages are also available.
376 if [ ${DONOTWAIT} -eq 0 ]
378 if [ ! -z "${NETDATA_PREFIX}" ]
380 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"
382 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"
387 netdata_banner "sorry, it failed to build..."
390 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
392 Sorry! netdata failed to build...
394 You many need to check these:
396 1. The package uuid-dev (or libuuid-devel) has to be installed.
398 If your system cannot find libuuid, although it is installed
399 run me with the option: --libs-are-really-here
401 2. The package zlib1g-dev (or zlib-devel) has to be installed.
403 If your system cannot find zlib, although it is installed
404 run me with the option: --libs-are-really-here
406 3. You need basic build tools installed, like:
408 gcc make autoconf automake pkg-config
410 Autoconf version 2.60 or higher is required.
412 If you still cannot get it to build, ask for help at github:
414 https://github.com/firehol/netdata/issues
422 if [ ${LIBS_ARE_HERE} -eq 1 ]
425 echo >&2 "ok, assuming libs are really installed."
426 export ZLIB_CFLAGS=" "
427 export ZLIB_LIBS="-lz"
428 export UUID_CFLAGS=" "
429 export UUID_LIBS="-luuid"
432 trap build_error EXIT
435 # -----------------------------------------------------------------------------
437 progress "Run autotools to configure the build environment"
439 if [ "$have_autotools" ]
441 run ./autogen.sh || exit 1
445 --prefix="${NETDATA_PREFIX}/usr" \
446 --sysconfdir="${NETDATA_PREFIX}/etc" \
447 --localstatedir="${NETDATA_PREFIX}/var" \
450 --with-user=netdata \
451 ${NETDATA_CONFIGURE_OPTIONS} \
452 CFLAGS="${CFLAGS}" || exit 1
454 # remove the build_error hook
457 # -----------------------------------------------------------------------------
458 progress "Cleanup compilation directory"
460 [ -f src/netdata ] && run make clean
462 # -----------------------------------------------------------------------------
463 progress "Compile netdata"
465 run make -j${processors} || exit 1
468 # -----------------------------------------------------------------------------
469 progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
471 # migrate existing configuration files
472 # for node.d and charts.d
473 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
475 # the configuration directory exists
477 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
479 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
482 # move the charts.d config files
483 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
485 for y in "" ".old" ".orig"
487 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
489 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
494 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
496 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
499 # move the node.d config files
500 for x in named sma_webbox snmp
502 for y in "" ".old" ".orig"
504 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
506 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
512 # -----------------------------------------------------------------------------
513 progress "Backup existing netdata configuration before installing it"
515 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
517 declare -A configs_signatures=()
518 if [ -f "configs.signatures" ]
520 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
524 config_signature_matches() {
525 local md5="${1}" file="${2}"
527 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
529 [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
533 if [ -f "configs.signatures" ]
535 grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null
542 # backup user configurations
543 installer_backup_suffix="${PID}.${RANDOM}"
544 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
548 # make a backup of the configuration file
549 cp -p "${x}" "${x}.old"
551 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
553 # we don't have md5sum - keep it
554 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
555 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
557 # find it relative filename
558 f="${x/*\/etc\/netdata\//}"
561 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
564 if [ -f "conf.d/${f}" ]
566 cp "conf.d/${f}" "${x}.orig"
569 if config_signature_matches "${md5}" "${f}"
571 # it is a stock version - don't keep it
572 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
574 # edited by user - keep it
575 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
576 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
580 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
582 rm -f "${x}.installer_backup.${installer_backup_suffix}"
587 # -----------------------------------------------------------------------------
588 progress "Install netdata"
590 run make install || exit 1
593 # -----------------------------------------------------------------------------
594 progress "Restore user edited netdata configuration files"
596 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
598 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
600 run cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \
601 run rm -f "${x}.installer_backup.${installer_backup_suffix}"
606 # -----------------------------------------------------------------------------
607 progress "Fix generated files permissions"
609 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
612 # -----------------------------------------------------------------------------
613 progress "Add user netdata to required user groups"
615 NETDATA_ADDED_TO_DOCKER=0
616 NETDATA_ADDED_TO_NGINX=0
617 NETDATA_ADDED_TO_VARNISH=0
618 NETDATA_ADDED_TO_HAPROXY=0
619 NETDATA_ADDED_TO_ADM=0
620 NETDATA_ADDED_TO_NSD=0
623 portable_add_group netdata
624 portable_add_user netdata
625 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
626 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
627 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
628 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
629 portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
630 portable_add_user_to_group nsd netdata && NETDATA_ADDED_TO_NSD=1
633 run_failed "The installer does not run as root."
636 # -----------------------------------------------------------------------------
637 progress "Install logrotate configuration for netdata"
641 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
643 run cp system/netdata.logrotate /etc/logrotate.d/netdata
646 if [ -f /etc/logrotate.d/netdata ]
648 run chmod 644 /etc/logrotate.d/netdata
653 # -----------------------------------------------------------------------------
654 progress "Read installation options from netdata.conf"
656 # create an empty config if it does not exist
657 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && \
658 touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
660 # function to extract values from the config file
662 local key="${1}" value="${2}" line=
664 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
666 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
667 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
673 # the user netdata will run as
674 if [ "${UID}" = "0" ]
676 NETDATA_USER="$( config_option "run as user" "netdata" )"
678 NETDATA_USER="${USER}"
681 # the owners of the web files
682 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
683 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
686 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
690 NETDATA_PORT="$( config_option "default port" ${defport} )"
691 NETDATA_PORT2="$( config_option "port" ${defport} )"
693 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
695 if [ "${NETDATA_PORT2}" != "${defport}" ]
697 NETDATA_PORT="${NETDATA_PORT2}"
702 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
703 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
704 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
705 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
706 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
707 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
710 # -----------------------------------------------------------------------------
711 progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
713 if [ ! -d "${NETDATA_RUN_DIR}" ]
715 # this is needed if NETDATA_PREFIX is not empty
716 run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
721 for x in "python.d" "charts.d" "node.d"
723 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
725 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
726 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
729 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
730 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
731 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
735 if [ ! -d "${NETDATA_WEB_DIR}" ]
737 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
738 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
740 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
741 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
742 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
746 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
750 echo >&2 "Creating directory '${x}'"
751 run mkdir -p "${x}" || exit 1
754 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
755 #run find "${x}" -type f -exec chmod 0660 {} \;
756 #run find "${x}" -type d -exec chmod 0770 {} \;
759 run chmod 755 "${NETDATA_LOG_DIR}"
765 # find the admin group
767 test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
768 test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon"
769 test -z "${admin_group}" && admin_group="${NETDATA_USER}"
771 run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
772 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
773 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
774 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
775 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
776 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
781 if [ ! -z "${setcap}" ]
783 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
787 if [ ${setcap_ret} -eq 0 ]
789 # if we managed to setcap
790 # but we fail to execute apps.plugin
791 # trigger setuid to root
792 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1
797 if [ ${setcap_ret} -ne 0 ]
799 # fix apps.plugin to be setuid to root
800 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
801 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
804 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]
806 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
807 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
811 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
812 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
813 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
814 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
817 # --- fix #1292 bug ---
819 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
820 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
824 # -----------------------------------------------------------------------------
825 progress "Install netdata at system init"
828 install_non_systemd_init() {
829 [ "${UID}" != 0 ] && return 1
832 if [ -f /etc/os-release ]
834 source /etc/os-release || return 1
835 key="${ID}-${VERSION_ID}"
837 elif [ -f /etc/centos-release ]
839 key=$(</etc/centos-release)
842 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
844 if [ "${key}" = "gentoo" ]
846 run cp system/netdata-openrc /etc/init.d/netdata && \
847 run chmod 755 /etc/init.d/netdata && \
848 run rc-update add netdata default && \
851 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
853 run cp system/netdata-lsb /etc/init.d/netdata && \
854 run chmod 755 /etc/init.d/netdata && \
855 run update-rc.d netdata defaults && \
856 run update-rc.d netdata enable && \
859 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
861 run cp system/netdata-init-d /etc/init.d/netdata && \
862 run chmod 755 /etc/init.d/netdata && \
863 run chkconfig netdata on && \
871 if [ "${UID}" -eq 0 ]
876 # systemd is running on this system
878 if [ ! -f /etc/systemd/system/netdata.service ]
880 echo >&2 "Installing systemd service..."
881 run cp system/netdata.service /etc/systemd/system/netdata.service && \
882 run systemctl daemon-reload && \
883 run systemctl enable netdata
886 install_non_systemd_init
891 # -----------------------------------------------------------------------------
892 # check if we can re-start netdata
899 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
900 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
906 stop_netdata_on_pid() {
907 local pid="${1}" ret=0 count=0
909 isnetdata ${pid} || return 0
911 printf >&2 "Stopping netdata on pid ${pid} ..."
912 while [ ! -z "$pid" -a ${ret} -eq 0 ]
914 if [ ${count} -gt 45 ]
916 echo >&2 "Cannot stop the running netdata on pid ${pid}."
920 count=$(( count + 1 ))
922 run kill ${pid} 2>/dev/null
925 test ${ret} -eq 0 && printf >&2 "." && sleep 2
931 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
935 echo >&2 "netdata on pid ${pid} stopped."
942 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
944 # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
946 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
947 $(cat /var/run/netdata.pid 2>/dev/null) \
948 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
949 $(pidof netdata 2>/dev/null)
951 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
953 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
955 stop_netdata_on_pid ${p}
960 if [ ${DONOTSTART} -eq 1 ]
962 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
964 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
966 if [ "${UID}" -eq 0 ]
968 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
970 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
975 progress "Start netdata"
977 if [ "${UID}" -eq 0 ]
981 service netdata restart && started=1
982 if [ ${started} -eq 0 ]
984 service netdata start && started=1
988 if [ ${started} -eq 0 ]
990 # still not started...
994 echo >&2 "Starting netdata..."
995 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
999 echo >&2 "SORRY! FAILED TO START NETDATA!"
1002 echo >&2 "OK. NetData Started!"
1008 # -----------------------------------------------------------------------------
1009 # save a config file, if it is not already there
1011 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
1014 echo >&2 "-------------------------------------------------------------------------------"
1016 echo >&2 "Downloading default configuration from netdata..."
1019 # remove a possibly obsolete download
1020 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1022 # disable a proxy to get data from the local netdata
1027 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1031 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1033 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1037 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1039 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1040 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1042 if [ "${UID}" -eq 0 ]
1044 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1046 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1048 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1049 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1054 # -----------------------------------------------------------------------------
1055 progress "Check KSM (kernel memory deduper)"
1057 ksm_is_available_but_disabled() {
1060 ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
1062 You have kernel memory de-duper (called Kernel Same-page Merging,
1063 or KSM) available, but it is not currently enabled.
1067 ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
1068 ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
1070 If you enable it, you will save 40-60% of netdata memory.
1075 ksm_is_not_available() {
1078 ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
1080 It seems you do not have kernel memory de-duper (called Kernel Same-page
1081 Merging, or KSM) available.
1083 To enable it, you need a kernel built with CONFIG_KSM=y
1085 If you can have it, you will save 40-60% of netdata memory.
1090 if [ -f "/sys/kernel/mm/ksm/run" ]
1092 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1094 ksm_is_available_but_disabled
1097 ksm_is_not_available
1100 # -----------------------------------------------------------------------------
1101 progress "Check version.txt"
1103 if [ ! -s web/version.txt ]
1107 ${TPUT_BOLD}Version update check warning${TPUT_RESET}
1109 The way you downloaded netdata, we cannot find its version. This means the
1110 Update check on the dashboard, will not work.
1112 If you want to have version update check, please re-install it
1113 following the procedure in:
1115 https://github.com/firehol/netdata/wiki/Installation
1120 # -----------------------------------------------------------------------------
1121 progress "Check apps.plugin"
1123 if [ "${UID}" -ne 0 ]
1125 cat <<SETUID_WARNING
1127 ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
1129 Since you have installed netdata as a normal user, to have apps.plugin collect
1130 all the needed data, you have to give it the access rights it needs, by running
1131 either of the following sets of commands:
1133 To run apps.plugin with escalated capabilities:
1135 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_USER} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1136 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1137 ${TPUT_YELLOW}${TPUT_BOLD}sudo setcap cap_dac_read_search,cap_sys_ptrace+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1139 or, to run apps.plugin as root:
1141 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1142 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4755 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1144 apps.plugin is performing a hard-coded function of data collection for all
1145 running processes. It cannot be instructed from the netdata daemon to perform
1146 any task, so it is pretty safe to do this.
1151 # -----------------------------------------------------------------------------
1152 progress "Generate netdata-uninstaller.sh"
1154 cat >netdata-uninstaller.sh <<UNINSTALL
1157 # this script will uninstall netdata
1159 if [ "\$1" != "--force" ]
1161 echo >&2 "This script will REMOVE netdata from your system."
1162 echo >&2 "Run it again with --force to do it."
1166 echo >&2 "Stopping a possibly running netdata..."
1167 for p in \$(pidof netdata); do kill \$p; done
1171 if [ ! -z "\$1" -a -d "\$1" ]
1174 echo "Deleting directory '\$1' ..."
1179 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1181 # installation prefix was given
1183 deletedir "${NETDATA_PREFIX}"
1186 # installation prefix was NOT given
1188 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1190 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1191 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1194 deletedir "${NETDATA_PREFIX}/etc/netdata"
1195 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1196 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1197 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1198 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1199 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1202 if [ -f /etc/logrotate.d/netdata ]
1204 echo "Deleting /etc/logrotate.d/netdata ..."
1205 rm -i /etc/logrotate.d/netdata
1208 if [ -f /etc/systemd/system/netdata.service ]
1210 echo "Deleting /etc/systemd/system/netdata.service ..."
1211 rm -i /etc/systemd/system/netdata.service
1214 if [ -f /etc/init.d/netdata ]
1216 echo "Deleting /etc/init.d/netdata ..."
1217 rm -i /etc/init.d/netdata
1220 getent passwd netdata > /dev/null
1224 echo "You may also want to remove the user netdata"
1226 echo " userdel netdata"
1229 getent group netdata > /dev/null
1233 echo "You may also want to remove the group netdata"
1235 echo " groupdel netdata"
1238 getent group docker > /dev/null
1239 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1242 echo "You may also want to remove the netdata user from the docker group"
1244 echo " gpasswd -d netdata docker"
1247 getent group nginx > /dev/null
1248 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1251 echo "You may also want to remove the netdata user from the nginx group"
1253 echo " gpasswd -d netdata nginx"
1256 getent group varnish > /dev/null
1257 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1260 echo "You may also want to remove the netdata user from the varnish group"
1262 echo " gpasswd -d netdata varnish"
1265 getent group haproxy > /dev/null
1266 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1269 echo "You may also want to remove the netdata user from the haproxy group"
1271 echo " gpasswd -d netdata haproxy"
1274 getent group adm > /dev/null
1275 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_ADM}" = "1" ]
1278 echo "You may also want to remove the netdata user from the adm group"
1280 echo " gpasswd -d netdata adm"
1283 getent group nsd > /dev/null
1284 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NSD}" = "1" ]
1287 echo "You may also want to remove the netdata user from the nsd group"
1289 echo " gpasswd -d netdata nsd"
1294 chmod 750 netdata-uninstaller.sh
1296 # -----------------------------------------------------------------------------
1297 progress "Basic netdata instructions"
1301 netdata by default listens on all IPs on port ${NETDATA_PORT},
1302 so you can access it with:
1304 ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
1306 To stop netdata, just kill it, with:
1308 ${TPUT_YELLOW}${TPUT_BOLD}killall netdata${TPUT_RESET}
1310 To start it, just run it:
1312 ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
1316 echo >&2 "Uninstall script generated: ${TPUT_RED}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}"
1320 cat >netdata-updater.sh.new <<REINSTALL
1324 [ "\${1}" = "-f" ] && force=1
1326 export PATH="\${PATH}:${PATH}"
1327 export CFLAGS="${CFLAGS}"
1328 export NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
1330 INSTALL_UID="${UID}"
1331 if [ "\${INSTALL_UID}" != "\${UID}" ]
1333 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1337 # make sure we cd to the working directory
1338 cd "${REINSTALL_PWD}" || exit 1
1340 # make sure there is .git here
1341 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1343 # signal netdata to start saving its database
1344 # this is handy if your database is big
1345 pids=\$(pidof netdata)
1346 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1351 # we are running on a terminal
1352 # open fd 3 and send it to stderr
1356 # create a temporary file for the log
1357 tmp=\$(mktemp /tmp/netdata-updater.log.XXXXXX)
1358 # open fd 3 and send it to tmp
1363 echo >&3 "\$(date) : INFO: " "\${@}"
1371 echo >&3 "\$(date) : ERROR: " "\${@}"
1374 # this is what we will do if it fails (head-less only)
1376 error "FAILED TO UPDATE NETDATA : \${1}"
1378 if [ ! -z "\${tmp}" ]
1386 get_latest_commit_id() {
1388 grep ^commit 2>&3 |\\
1390 cut -d ' ' -f 2 2>&3
1394 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1400 info "Updating netdata source from github..."
1402 last_commit="\$(get_latest_commit_id)"
1403 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1405 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1407 new_commit="\$(get_latest_commit_id)"
1408 if [ \${force} -eq 0 ]
1410 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1411 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1413 elif [ \${force} -eq 0 ]
1415 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1419 info "Re-installing netdata..."
1420 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1422 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1426 # the installer updates this script - so we run and exit in a single line
1428 ###############################################################################
1429 ###############################################################################
1431 chmod 755 netdata-updater.sh.new
1432 mv -f netdata-updater.sh.new netdata-updater.sh
1433 echo >&2 "Update script generated : ${TPUT_GREEN}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}"
1435 echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} can work from cron. It will trigger an email from cron"
1436 echo >&2 "only if it fails (it does not print anything if it can update netdata).${TPUT_RESET}"
1437 if [ "${UID}" -eq "0" ]
1439 if [ -d "/etc/cron.daily" -a ! -f "/etc/cron.daily/netdata-updater.sh" ]
1441 echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}"
1443 echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}ln -s ${PWD}/netdata-updater.sh /etc/cron.daily/netdata-updater.sh${TPUT_RESET}"
1444 elif [ -d "/etc/periodic/daily" -a ! -f "/etc/periodic/daily/netdata-updater" ]
1446 echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}"
1448 echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}ln -s ${PWD}/netdata-updater.sh /etc/periodic/daily/netdata-updater${TPUT_RESET}"
1451 elif [ -f "netdata-updater.sh" ]
1453 rm "netdata-updater.sh"
1456 # -----------------------------------------------------------------------------
1458 progress "We are done!"
1460 if [ ${started} -eq 1 ]
1462 netdata_banner "is installed and running now!"
1464 netdata_banner "is installed now!"
1467 echo >&2 " enjoy real-time performance and health monitoring..."