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 --zlib-is-really-here
108 --libs-are-really-here
110 If you get errors about missing zlib,
111 or libuuid but you know it is available,
112 you have a broken pkg-config.
113 Use this option to allow it continue
114 without checking pkg-config.
116 Netdata will by default be compiled with gcc optimization -O2
117 If you need to pass different CFLAGS, use something like this:
119 CFLAGS="<gcc options>" ${ME} <installer options>
121 For the installer to complete successfully, you will need
122 these packages installed:
124 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
125 uuid-dev (or libuuid-devel)
127 For the plugins, you will at least need:
134 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
135 get_git_config_signatures() {
138 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
139 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
141 echo >configs.signatures.tmp
143 for x in $(find conf.d -name \*.conf)
147 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
149 git checkout ${c} "conf.d/${x}" || continue
150 s="$(cat "conf.d/${x}" | ${md5sum} | cut -d ' ' -f 1)"
151 echo >>configs.signatures.tmp "${s}:${x}"
154 git checkout HEAD "conf.d/${x}" || break
157 cat configs.signatures.tmp |\
161 echo "declare -A configs_signatures=("
165 echo " ['${md5}']='${file}'"
168 } >configs.signatures
170 rm configs.signatures.tmp
176 while [ ! -z "${1}" ]
178 if [ "$1" = "--install" ]
180 NETDATA_PREFIX="${2}/netdata"
182 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
186 elif [ "$1" = "--dont-start-it" ]
190 elif [ "$1" = "--dont-wait" ]
194 elif [ "$1" = "--enable-plugin-freeipmi" ]
196 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-freeipmi"
198 elif [ "$1" = "--disable-plugin-freeipmi" ]
200 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-plugin-freeipmi"
202 elif [ "$1" = "--help" -o "$1" = "-h" ]
206 elif [ "$1" = "get_git_config_signatures" ]
208 get_git_config_signatures && exit 0
213 echo >&2 "I cannot understand option '$1'."
219 netdata_banner "real-time performance monitoring, done right!"
222 You are about to build and install netdata to your system.
224 It will be installed at these locations:
226 - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
227 - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
228 - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
229 - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
230 - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
231 - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
232 - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
235 [ "${UID}" -eq 0 ] && cat <<BANNER2
236 - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
237 - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
242 This installer allows you to change the installation path.
243 Press Control-C and run the same command with --help for help.
247 if [ "${UID}" -ne 0 ]
249 if [ -z "${NETDATA_PREFIX}" ]
251 netdata_banner "wrong command line options!"
252 cat <<NONROOTNOPREFIX
254 ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
256 You are attempting to install netdata as non-root, but you plan
257 to install it in system paths.
259 Please set an installation prefix, like this:
261 $0 ${@} --install /tmp
263 or, run the installer as root:
267 We suggest to install it as root, or certain data collectors will
268 not be able to work. Netdata drops root privileges when running.
269 So, if you plan to keep it, install it as root to get the full
278 ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
279 You are about to install netdata as a non-root user.
280 Netdata will work, but a few data collection modules that
281 require root access will fail.
283 If you installing netdata permanently on your system, run
284 the installer like this:
286 ${TPUT_YELLOW}${TPUT_BOLD}sudo $0 ${@}${TPUT_RESET}
293 if [ "$(type autoreconf 2> /dev/null)" ]
301 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
302 eval $maj=\$1 $min=\$2
304 autoconf_maj_min AMAJ AMIN
309 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
313 echo "Found autotools $AMAJ.$AMIN"
316 echo "No autotools found"
319 if [ ! "$have_autotools" ]
323 echo "Will skip autoreconf step"
325 netdata_banner "autotools v2.60 required"
328 -------------------------------------------------------------------------------
329 autotools 2.60 or later is required
331 Sorry, you do not seem to have autotools 2.60 or later, which is
332 required to build from the git sources of netdata.
334 You can either install a suitable version of autotools and automake
335 or download a netdata package which does not have these dependencies.
337 Source packages where autotools have already been run are available
339 https://firehol.org/download/netdata/
341 The unsigned/master folder tracks the head of the git tree and released
342 packages are also available.
348 if [ ${DONOTWAIT} -eq 0 ]
350 if [ ! -z "${NETDATA_PREFIX}" ]
352 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"
354 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"
359 netdata_banner "sorry, it failed to build..."
362 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
364 Sorry! netdata failed to build...
366 You many need to check these:
368 1. The package uuid-dev (or libuuid-devel) has to be installed.
370 If your system cannot find libuuid, although it is installed
371 run me with the option: --libs-are-really-here
373 2. The package zlib1g-dev (or zlib-devel) has to be installed.
375 If your system cannot find zlib, although it is installed
376 run me with the option: --libs-are-really-here
378 3. You need basic build tools installed, like:
380 gcc make autoconf automake pkg-config
382 Autoconf version 2.60 or higher is required.
384 If you still cannot get it to build, ask for help at github:
386 https://github.com/firehol/netdata/issues
394 if [ ${LIBS_ARE_HERE} -eq 1 ]
397 echo >&2 "ok, assuming libs are really installed."
398 export ZLIB_CFLAGS=" "
399 export ZLIB_LIBS="-lz"
400 export UUID_CFLAGS=" "
401 export UUID_LIBS="-luuid"
404 trap build_error EXIT
407 # -----------------------------------------------------------------------------
409 progress "Run autotools to configure the build environment"
411 if [ "$have_autotools" ]
413 run ./autogen.sh || exit 1
417 --prefix="${NETDATA_PREFIX}/usr" \
418 --sysconfdir="${NETDATA_PREFIX}/etc" \
419 --localstatedir="${NETDATA_PREFIX}/var" \
422 --with-user=netdata \
423 ${NETDATA_CONFIGURE_OPTIONS} \
424 CFLAGS="${CFLAGS}" || exit 1
426 # remove the build_error hook
429 # -----------------------------------------------------------------------------
430 progress "Cleanup compilation directory"
432 [ -f src/netdata ] && run make clean
434 # -----------------------------------------------------------------------------
435 progress "Compile netdata"
437 run make -j${processors} || exit 1
440 # -----------------------------------------------------------------------------
441 progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
443 # migrate existing configuration files
444 # for node.d and charts.d
445 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
447 # the configuration directory exists
449 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
451 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
454 # move the charts.d config files
455 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
457 for y in "" ".old" ".orig"
459 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
461 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
466 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
468 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
471 # move the node.d config files
472 for x in named sma_webbox snmp
474 for y in "" ".old" ".orig"
476 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
478 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
484 # -----------------------------------------------------------------------------
485 progress "Backup existing netdata configuration before installing it"
487 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
489 declare -A configs_signatures=()
490 if [ -f "configs.signatures" ]
492 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
496 # backup user configurations
497 installer_backup_suffix="${PID}.${RANDOM}"
498 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
502 # make a backup of the configuration file
503 cp -p "${x}" "${x}.old"
505 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
507 # we don't have md5sum - keep it
508 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
509 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
511 # find it relative filename
512 f="${x/*\/etc\/netdata\//}"
515 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
518 if [ -f "conf.d/${f}" ]
520 cp "conf.d/${f}" "${x}.orig"
523 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
525 if [ "${configs_signatures[${md5}]}" = "${f}" ]
527 # it is a stock version - don't keep it
528 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
530 # edited by user - keep it
531 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
532 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
535 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}cannot be checked for custom edits${TPUT_RESET}. Keeping it."
536 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
540 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
542 rm -f "${x}.installer_backup.${installer_backup_suffix}"
547 # -----------------------------------------------------------------------------
548 progress "Install netdata"
550 run make install || exit 1
553 # -----------------------------------------------------------------------------
554 progress "Restore user edited netdata configuration files"
556 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
558 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
560 run cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \
561 run rm -f "${x}.installer_backup.${installer_backup_suffix}"
566 # -----------------------------------------------------------------------------
567 progress "Fix generated files permissions"
569 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
572 # -----------------------------------------------------------------------------
573 progress "Add user netdata to required user groups"
575 NETDATA_ADDED_TO_DOCKER=0
576 NETDATA_ADDED_TO_NGINX=0
577 NETDATA_ADDED_TO_VARNISH=0
578 NETDATA_ADDED_TO_HAPROXY=0
579 NETDATA_ADDED_TO_ADM=0
582 portable_add_group netdata
583 portable_add_user netdata
584 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
585 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
586 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
587 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
588 portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
591 run_failed "The installer does not run as root."
594 # -----------------------------------------------------------------------------
595 progress "Install logrotate configuration for netdata"
599 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
601 run cp system/netdata.logrotate /etc/logrotate.d/netdata
604 if [ -f /etc/logrotate.d/netdata ]
606 run chmod 644 /etc/logrotate.d/netdata
611 # -----------------------------------------------------------------------------
612 progress "Read installation options from netdata.conf"
614 # create an empty config if it does not exist
615 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && \
616 touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
618 # function to extract values from the config file
620 local key="${1}" value="${2}" line=
622 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
624 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
625 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
631 # the user netdata will run as
632 if [ "${UID}" = "0" ]
634 NETDATA_USER="$( config_option "run as user" "netdata" )"
636 NETDATA_USER="${USER}"
639 # the owners of the web files
640 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
641 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
644 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
648 NETDATA_PORT="$( config_option "default port" ${defport} )"
649 NETDATA_PORT2="$( config_option "port" ${defport} )"
651 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
653 if [ "${NETDATA_PORT2}" != "${defport}" ]
655 NETDATA_PORT="${NETDATA_PORT2}"
660 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
661 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
662 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
663 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
664 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
665 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
668 # -----------------------------------------------------------------------------
669 progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
671 if [ ! -d "${NETDATA_RUN_DIR}" ]
673 # this is needed if NETDATA_PREFIX is not empty
674 run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
679 for x in "python.d" "charts.d" "node.d"
681 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
683 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
684 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
687 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
688 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
689 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
693 if [ ! -d "${NETDATA_WEB_DIR}" ]
695 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
696 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
698 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
699 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
700 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
704 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
708 echo >&2 "Creating directory '${x}'"
709 run mkdir -p "${x}" || exit 1
712 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
713 #run find "${x}" -type f -exec chmod 0660 {} \;
714 #run find "${x}" -type d -exec chmod 0770 {} \;
717 run chmod 755 "${NETDATA_LOG_DIR}"
723 # find the admin group
725 test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
726 test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon"
727 test -z "${admin_group}" && admin_group="${NETDATA_USER}"
729 run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
730 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
731 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
732 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
733 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
734 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
739 if [ ! -z "${setcap}" ]
741 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
745 if [ ${setcap_ret} -eq 0 ]
747 # if we managed to setcap
748 # but we fail to execute apps.plugin
749 # trigger setuid to root
750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1
755 if [ ${setcap_ret} -ne 0 ]
757 # fix apps.plugin to be setuid to root
758 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
759 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
762 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]
764 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
765 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
769 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
770 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
771 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
772 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
775 # --- fix #1292 bug ---
777 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
778 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
782 # -----------------------------------------------------------------------------
783 progress "Install netdata at system init"
786 install_non_systemd_init() {
787 [ "${UID}" != 0 ] && return 1
790 if [ -f /etc/os-release ]
792 source /etc/os-release || return 1
793 key="${ID}-${VERSION_ID}"
795 elif [ -f /etc/centos-release ]
797 key=$(</etc/centos-release)
800 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
802 if [ "${key}" = "gentoo" ]
804 run cp system/netdata-openrc /etc/init.d/netdata && \
805 run chmod 755 /etc/init.d/netdata && \
806 run rc-update add netdata default && \
809 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
811 run cp system/netdata-lsb /etc/init.d/netdata && \
812 run chmod 755 /etc/init.d/netdata && \
813 run update-rc.d netdata defaults && \
814 run update-rc.d netdata enable && \
817 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
819 run cp system/netdata-init-d /etc/init.d/netdata && \
820 run chmod 755 /etc/init.d/netdata && \
821 run chkconfig netdata on && \
829 if [ "${UID}" -eq 0 ]
834 # systemd is running on this system
836 if [ ! -f /etc/systemd/system/netdata.service ]
838 echo >&2 "Installing systemd service..."
839 run cp system/netdata.service /etc/systemd/system/netdata.service && \
840 run systemctl daemon-reload && \
841 run systemctl enable netdata
844 install_non_systemd_init
849 # -----------------------------------------------------------------------------
850 # check if we can re-start netdata
857 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
858 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
864 stop_netdata_on_pid() {
865 local pid="${1}" ret=0 count=0
867 isnetdata ${pid} || return 0
869 printf >&2 "Stopping netdata on pid ${pid} ..."
870 while [ ! -z "$pid" -a ${ret} -eq 0 ]
872 if [ ${count} -gt 45 ]
874 echo >&2 "Cannot stop the running netdata on pid ${pid}."
878 count=$(( count + 1 ))
880 run kill ${pid} 2>/dev/null
883 test ${ret} -eq 0 && printf >&2 "." && sleep 2
889 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
893 echo >&2 "netdata on pid ${pid} stopped."
900 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
902 # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
904 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
905 $(cat /var/run/netdata.pid 2>/dev/null) \
906 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
907 $(pidof netdata 2>/dev/null)
909 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
911 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
913 stop_netdata_on_pid ${p}
918 if [ ${DONOTSTART} -eq 1 ]
920 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
922 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
924 if [ "${UID}" -eq 0 ]
926 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
928 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
933 progress "Start netdata"
935 if [ "${UID}" -eq 0 ]
939 service netdata restart && started=1
940 if [ ${started} -eq 0 ]
942 service netdata start && started=1
946 if [ ${started} -eq 0 ]
948 # still not started...
952 echo >&2 "Starting netdata..."
953 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
957 echo >&2 "SORRY! FAILED TO START NETDATA!"
960 echo >&2 "OK. NetData Started!"
966 # -----------------------------------------------------------------------------
967 # save a config file, if it is not already there
969 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
972 echo >&2 "-------------------------------------------------------------------------------"
974 echo >&2 "Downloading default configuration from netdata..."
977 # remove a possibly obsolete download
978 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
980 # disable a proxy to get data from the local netdata
985 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
989 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
991 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
995 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
997 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
998 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1000 if [ "${UID}" -eq 0 ]
1002 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1004 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1006 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1007 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1012 # -----------------------------------------------------------------------------
1013 progress "Check KSM (kernel memory deduper)"
1015 ksm_is_available_but_disabled() {
1018 ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
1020 You have kernel memory de-duper (called Kernel Same-page Merging,
1021 or KSM) available, but it is not currently enabled.
1025 ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
1026 ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
1028 If you enable it, you will save 40-60% of netdata memory.
1033 ksm_is_not_available() {
1036 ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
1038 It seems you do not have kernel memory de-duper (called Kernel Same-page
1039 Merging, or KSM) available.
1041 To enable it, you need a kernel built with CONFIG_KSM=y
1043 If you can have it, you will save 40-60% of netdata memory.
1048 if [ -f "/sys/kernel/mm/ksm/run" ]
1050 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1052 ksm_is_available_but_disabled
1055 ksm_is_not_available
1058 # -----------------------------------------------------------------------------
1059 progress "Check version.txt"
1061 if [ ! -s web/version.txt ]
1065 ${TPUT_BOLD}Version update check warning${TPUT_RESET}
1067 The way you downloaded netdata, we cannot find its version. This means the
1068 Update check on the dashboard, will not work.
1070 If you want to have version update check, please re-install it
1071 following the procedure in:
1073 https://github.com/firehol/netdata/wiki/Installation
1078 # -----------------------------------------------------------------------------
1079 progress "Check apps.plugin"
1081 if [ "${UID}" -ne 0 ]
1083 cat <<SETUID_WARNING
1085 ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
1087 Since you have installed netdata as a normal user, to have apps.plugin collect
1088 all the needed data, you have to give it the access rights it needs, by running
1089 either of the following sets of commands:
1091 To run apps.plugin with escalated capabilities:
1093 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_USER} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1094 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1095 ${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}
1097 or, to run apps.plugin as root:
1099 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1100 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4755 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1102 apps.plugin is performing a hard-coded function of data collection for all
1103 running processes. It cannot be instructed from the netdata daemon to perform
1104 any task, so it is pretty safe to do this.
1109 # -----------------------------------------------------------------------------
1110 progress "Generate netdata-uninstaller.sh"
1112 cat >netdata-uninstaller.sh <<UNINSTALL
1115 # this script will uninstall netdata
1117 if [ "\$1" != "--force" ]
1119 echo >&2 "This script will REMOVE netdata from your system."
1120 echo >&2 "Run it again with --force to do it."
1124 echo >&2 "Stopping a possibly running netdata..."
1125 for p in \$(pidof netdata); do kill \$p; done
1129 if [ ! -z "\$1" -a -d "\$1" ]
1132 echo "Deleting directory '\$1' ..."
1137 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1139 # installation prefix was given
1141 deletedir "${NETDATA_PREFIX}"
1144 # installation prefix was NOT given
1146 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1148 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1149 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1152 deletedir "${NETDATA_PREFIX}/etc/netdata"
1153 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1154 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1155 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1156 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1157 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1160 if [ -f /etc/logrotate.d/netdata ]
1162 echo "Deleting /etc/logrotate.d/netdata ..."
1163 rm -i /etc/logrotate.d/netdata
1166 if [ -f /etc/systemd/system/netdata.service ]
1168 echo "Deleting /etc/systemd/system/netdata.service ..."
1169 rm -i /etc/systemd/system/netdata.service
1172 if [ -f /etc/init.d/netdata ]
1174 echo "Deleting /etc/init.d/netdata ..."
1175 rm -i /etc/init.d/netdata
1178 getent passwd netdata > /dev/null
1182 echo "You may also want to remove the user netdata"
1184 echo " userdel netdata"
1187 getent group netdata > /dev/null
1191 echo "You may also want to remove the group netdata"
1193 echo " groupdel netdata"
1196 getent group docker > /dev/null
1197 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1200 echo "You may also want to remove the netdata user from the docker group"
1202 echo " gpasswd -d netdata docker"
1205 getent group nginx > /dev/null
1206 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1209 echo "You may also want to remove the netdata user from the nginx group"
1211 echo " gpasswd -d netdata nginx"
1214 getent group varnish > /dev/null
1215 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1218 echo "You may also want to remove the netdata user from the varnish group"
1220 echo " gpasswd -d netdata varnish"
1223 getent group haproxy > /dev/null
1224 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1227 echo "You may also want to remove the netdata user from the haproxy group"
1229 echo " gpasswd -d netdata haproxy"
1232 getent group adm > /dev/null
1233 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_ADM}" = "1" ]
1236 echo "You may also want to remove the netdata user from the adm group"
1238 echo " gpasswd -d netdata adm"
1243 chmod 750 netdata-uninstaller.sh
1245 # -----------------------------------------------------------------------------
1246 progress "Basic netdata instructions"
1250 netdata by default listens on all IPs on port ${NETDATA_PORT},
1251 so you can access it with:
1253 ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
1255 To stop netdata, just kill it, with:
1257 ${TPUT_YELLOW}${TPUT_BOLD}killall netdata${TPUT_RESET}
1259 To start it, just run it:
1261 ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
1265 echo >&2 "Uninstall script generated: ${TPUT_RED}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}"
1269 cat >netdata-updater.sh.new <<REINSTALL
1273 [ "\${1}" = "-f" ] && force=1
1275 export PATH="\${PATH}:${PATH}"
1276 export CFLAGS="${CFLAGS}"
1277 export NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
1279 INSTALL_UID="${UID}"
1280 if [ "\${INSTALL_UID}" != "\${UID}" ]
1282 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1286 # make sure we cd to the working directory
1287 cd "${REINSTALL_PWD}" || exit 1
1289 # make sure there is .git here
1290 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1292 # signal netdata to start saving its database
1293 # this is handy if your database is big
1294 pids=\$(pidof netdata)
1295 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1300 # we are running on a terminal
1301 # open fd 3 and send it to stderr
1305 # create a temporary file for the log
1306 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1307 # open fd 3 and send it to tmp
1312 echo >&3 "\$(date) : INFO: " "\${@}"
1320 echo >&3 "\$(date) : ERROR: " "\${@}"
1323 # this is what we will do if it fails (head-less only)
1325 error "FAILED TO UPDATE NETDATA : \${1}"
1327 if [ ! -z "\${tmp}" ]
1335 get_latest_commit_id() {
1337 grep ^commit 2>&3 |\\
1339 cut -d ' ' -f 2 2>&3
1343 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1349 info "Updating netdata source from github..."
1351 last_commit="\$(get_latest_commit_id)"
1352 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1354 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1356 new_commit="\$(get_latest_commit_id)"
1357 if [ \${force} -eq 0 ]
1359 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1360 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1362 elif [ \${force} -eq 0 ]
1364 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1368 info "Re-installing netdata..."
1369 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1371 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1375 # the installer updates this script - so we run and exit in a single line
1377 ###############################################################################
1378 ###############################################################################
1380 chmod 755 netdata-updater.sh.new
1381 mv -f netdata-updater.sh.new netdata-updater.sh
1382 echo >&2 "Update script generated : ${TPUT_GREEN}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}"
1384 echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} can work from cron. It will trigger an email from cron"
1385 echo >&2 "only if it fails (it does not print anything if it can update netdata).${TPUT_RESET}"
1386 if [ "${UID}" -eq 0 -a -d "/etc/cron.daily" -a ! -f "/etc/cron.daily/netdata-updater.sh" ]
1388 echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}"
1390 echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}ln -s ${PWD}/netdata-updater.sh /etc/cron.daily/netdata-updater.sh${TPUT_RESET}"
1392 elif [ -f "netdata-updater.sh" ]
1394 rm "netdata-updater.sh"
1397 # -----------------------------------------------------------------------------
1399 progress "We are done!"
1401 if [ ${started} -eq 1 ]
1403 netdata_banner "is installed and running now!"
1405 netdata_banner "is installed now!"
1408 echo >&2 " enjoy real-time performance and health monitoring..."