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=$(grep ^processor </proc/cpuinfo 2>/dev/null | 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)"
78 netdata_banner "installer command line options"
81 ${ME} <installer options>
83 Valid <installer options> are:
85 --install /PATH/TO/INSTALL
87 If you give: --install /opt
88 netdata will be installed in /opt/netdata
92 Do not (re)start netdata.
97 Do not wait for the user to press ENTER.
98 Start immediately building it.
100 --zlib-is-really-here
101 --libs-are-really-here
103 If you get errors about missing zlib,
104 or libuuid but you know it is available,
105 you have a broken pkg-config.
106 Use this option to allow it continue
107 without checking pkg-config.
109 Netdata will by default be compiled with gcc optimization -O2
110 If you need to pass different CFLAGS, use something like this:
112 CFLAGS="<gcc options>" ${ME} <installer options>
114 For the installer to complete successfully, you will need
115 these packages installed:
117 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
118 uuid-dev (or libuuid-devel)
120 For the plugins, you will at least need:
127 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null)"
128 get_git_config_signatures() {
131 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
132 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
134 echo >configs.signatures.tmp
136 for x in $(find conf.d -name \*.conf)
140 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
142 git checkout ${c} "conf.d/${x}" || continue
143 s="$(cat "conf.d/${x}" | md5sum | cut -d ' ' -f 1)"
144 echo >>configs.signatures.tmp "${s}:${x}"
147 git checkout HEAD "conf.d/${x}" || break
150 cat configs.signatures.tmp |\
154 echo "declare -A configs_signatures=("
158 echo " ['${md5}']='${file}'"
161 } >configs.signatures
163 rm configs.signatures.tmp
169 while [ ! -z "${1}" ]
171 if [ "$1" = "--install" ]
173 NETDATA_PREFIX="${2}/netdata"
175 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
179 elif [ "$1" = "--dont-start-it" ]
183 elif [ "$1" = "--dont-wait" ]
187 elif [ "$1" = "--help" -o "$1" = "-h" ]
191 elif [ "$1" = "get_git_config_signatures" ]
193 get_git_config_signatures && exit 0
198 echo >&2 "I cannot understand option '$1'."
204 netdata_banner "real-time performance monitoring, done right!"
207 You are about to build and install netdata to your system.
209 It will be installed at these locations:
211 - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
212 - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
213 - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
214 - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
215 - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
216 - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
217 - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
220 [ "${UID}" -eq 0 ] && cat <<BANNER2
221 - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
222 - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
227 This installer allows you to change the installation path.
228 Press Control-C and run the same command with --help for help.
232 if [ "${UID}" -ne 0 ]
234 if [ -z "${NETDATA_PREFIX}" ]
236 netdata_banner "wrong command line options!"
237 cat <<NONROOTNOPREFIX
239 ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
241 You are attempting to install netdata as non-root, but you plan
242 to install it in system paths.
244 Please set an installation prefix, like this:
246 $0 ${@} --install /tmp
248 or, run the installer as root:
252 We suggest to install it as root, or certain data collectors will
253 not be able to work. Netdata drops root privileges when running.
254 So, if you plan to keep it, install it as root to get the full
263 ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
264 You are about to install netdata as a non-root user.
265 Netdata will work, but a few data collection modules that
266 require root access will fail.
268 If you installing netdata permanently on your system, run
269 the installer like this:
271 ${TPUT_YELLOW}${TPUT_BOLD}sudo $0 ${@}${TPUT_RESET}
278 if [ "$(type autoreconf 2> /dev/null)" ]
286 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
287 eval $maj=\$1 $min=\$2
289 autoconf_maj_min AMAJ AMIN
294 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
298 echo "Found autotools $AMAJ.$AMIN"
301 echo "No autotools found"
304 if [ ! "$have_autotools" ]
308 echo "Will skip autoreconf step"
310 netdata_banner "autotools v2.60 required"
313 -------------------------------------------------------------------------------
314 autotools 2.60 or later is required
316 Sorry, you do not seem to have autotools 2.60 or later, which is
317 required to build from the git sources of netdata.
319 You can either install a suitable version of autotools and automake
320 or download a netdata package which does not have these dependencies.
322 Source packages where autotools have already been run are available
324 https://firehol.org/download/netdata/
326 The unsigned/master folder tracks the head of the git tree and released
327 packages are also available.
333 if [ ${DONOTWAIT} -eq 0 ]
335 if [ ! -z "${NETDATA_PREFIX}" ]
337 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"
339 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"
344 netdata_banner "sorry, it failed to build..."
347 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
349 Sorry! netdata failed to build...
351 You many need to check these:
353 1. The package uuid-dev (or libuuid-devel) has to be installed.
355 If your system cannot find libuuid, although it is installed
356 run me with the option: --libs-are-really-here
358 2. The package zlib1g-dev (or zlib-devel) has to be installed.
360 If your system cannot find zlib, although it is installed
361 run me with the option: --libs-are-really-here
363 3. You need basic build tools installed, like:
365 gcc make autoconf automake pkg-config
367 Autoconf version 2.60 or higher is required.
369 If you still cannot get it to build, ask for help at github:
371 https://github.com/firehol/netdata/issues
379 if [ ${LIBS_ARE_HERE} -eq 1 ]
382 echo >&2 "ok, assuming libs are really installed."
383 export ZLIB_CFLAGS=" "
384 export ZLIB_LIBS="-lz"
385 export UUID_CFLAGS=" "
386 export UUID_LIBS="-luuid"
389 trap build_error EXIT
392 # -----------------------------------------------------------------------------
394 progress "Run autotools to configure the build environment"
396 if [ "$have_autotools" ]
398 run ./autogen.sh || exit 1
402 --prefix="${NETDATA_PREFIX}/usr" \
403 --sysconfdir="${NETDATA_PREFIX}/etc" \
404 --localstatedir="${NETDATA_PREFIX}/var" \
405 --with-zlib --with-math --with-user=netdata \
406 CFLAGS="${CFLAGS}" || exit 1
408 # remove the build_error hook
411 # -----------------------------------------------------------------------------
412 progress "Cleanup compilation directory"
414 [ -f src/netdata ] && run make clean
416 # -----------------------------------------------------------------------------
417 progress "Compile netdata"
419 run make -j${processors} || exit 1
422 # -----------------------------------------------------------------------------
423 progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
425 # migrate existing configuration files
426 # for node.d and charts.d
427 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
429 # the configuration directory exists
431 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
433 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
436 # move the charts.d config files
437 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
439 for y in "" ".old" ".orig"
441 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
443 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
448 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
450 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
453 # move the node.d config files
454 for x in named sma_webbox snmp
456 for y in "" ".old" ".orig"
458 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
460 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
466 # -----------------------------------------------------------------------------
467 progress "Backup existing netdata configuration before installing it"
469 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
471 declare -A configs_signatures=()
472 if [ -f "configs.signatures" ]
474 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
478 # backup user configurations
479 installer_backup_suffix="${PID}.${RANDOM}"
480 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
484 # make a backup of the configuration file
485 cp -p "${x}" "${x}.old"
487 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
489 # we don't have md5sum - keep it
490 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
491 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
493 # find it relative filename
494 f="${x/*\/etc\/netdata\//}"
497 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
500 if [ -f "conf.d/${f}" ]
502 cp "conf.d/${f}" "${x}.orig"
505 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
507 if [ "${configs_signatures[${md5}]}" = "${f}" ]
509 # it is a stock version - don't keep it
510 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
512 # edited by user - keep it
513 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
514 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
517 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}cannot be checked for custom edits${TPUT_RESET}. Keeping it."
518 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
522 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
524 rm -f "${x}.installer_backup.${installer_backup_suffix}"
529 # -----------------------------------------------------------------------------
530 progress "Install netdata"
532 run make install || exit 1
535 # -----------------------------------------------------------------------------
536 progress "Restore user edited netdata configuration files"
538 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
540 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
542 run cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \
543 run rm -f "${x}.installer_backup.${installer_backup_suffix}"
548 # -----------------------------------------------------------------------------
549 progress "Fix generated files permissions"
551 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
554 # -----------------------------------------------------------------------------
555 progress "Add user netdata to required user groups"
557 NETDATA_ADDED_TO_DOCKER=0
558 NETDATA_ADDED_TO_NGINX=0
559 NETDATA_ADDED_TO_VARNISH=0
560 NETDATA_ADDED_TO_HAPROXY=0
561 NETDATA_ADDED_TO_ADM=0
564 portable_add_group netdata
565 portable_add_user netdata
566 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
567 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
568 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
569 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
570 portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
573 run_failed "The installer does not run as root."
576 # -----------------------------------------------------------------------------
577 progress "Install logrotate configuration for netdata"
581 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
583 run cp system/netdata.logrotate /etc/logrotate.d/netdata
586 if [ -f /etc/logrotate.d/netdata ]
588 run chmod 644 /etc/logrotate.d/netdata
593 # -----------------------------------------------------------------------------
594 progress "Read installation options from netdata.conf"
596 # create an empty config if it does not exist
597 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && \
598 touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
600 # function to extract values from the config file
602 local key="${1}" value="${2}" line=
604 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
606 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
607 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
613 # the user netdata will run as
614 if [ "${UID}" = "0" ]
616 NETDATA_USER="$( config_option "run as user" "netdata" )"
618 NETDATA_USER="${USER}"
621 # the owners of the web files
622 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
623 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
626 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
630 NETDATA_PORT="$( config_option "default port" ${defport} )"
631 NETDATA_PORT2="$( config_option "port" ${defport} )"
633 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
635 if [ "${NETDATA_PORT2}" != "${defport}" ]
637 NETDATA_PORT="${NETDATA_PORT2}"
642 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
643 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
644 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
645 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
646 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
647 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
650 # -----------------------------------------------------------------------------
651 progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
653 if [ ! -d "${NETDATA_RUN_DIR}" ]
655 # this is needed if NETDATA_PREFIX is not empty
656 run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
661 for x in "python.d" "charts.d" "node.d"
663 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
665 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
666 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
669 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
670 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
671 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
675 if [ ! -d "${NETDATA_WEB_DIR}" ]
677 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
678 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
680 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
681 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
682 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
686 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
690 echo >&2 "Creating directory '${x}'"
691 run mkdir -p "${x}" || exit 1
694 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
695 #run find "${x}" -type f -exec chmod 0660 {} \;
696 #run find "${x}" -type d -exec chmod 0770 {} \;
699 run chmod 755 "${NETDATA_LOG_DIR}"
705 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
706 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
707 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
708 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
709 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
710 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
715 if [ ! -z "${setcap}" ]
717 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
721 if [ ${setcap_ret} -eq 0 ]
723 # if we managed to setcap
724 # but we fail to execute apps.plugin
725 # trigger setuid to root
726 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
731 if [ ${setcap_ret} -ne 0 ]
733 # fix apps.plugin to be setuid to root
734 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
735 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
738 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
739 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
740 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
741 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
744 # --- fix #1292 bug ---
746 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
747 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
751 # -----------------------------------------------------------------------------
752 progress "Install netdata at system init"
755 install_non_systemd_init() {
756 [ "${UID}" != 0 ] && return 1
759 if [ -f /etc/os-release ]
761 source /etc/os-release || return 1
762 key="${ID}-${VERSION_ID}"
764 elif [ -f /etc/centos-release ]
766 key=$(</etc/centos-release)
769 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
771 if [ "${key}" = "gentoo" ]
773 run cp system/netdata-openrc /etc/init.d/netdata && \
774 run chmod 755 /etc/init.d/netdata && \
775 run rc-update add netdata default && \
778 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
780 run cp system/netdata-lsb /etc/init.d/netdata && \
781 run chmod 755 /etc/init.d/netdata && \
782 run update-rc.d netdata defaults && \
783 run update-rc.d netdata enable && \
786 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
788 run cp system/netdata-init-d /etc/init.d/netdata && \
789 run chmod 755 /etc/init.d/netdata && \
790 run chkconfig netdata on && \
798 if [ "${UID}" -eq 0 ]
803 # systemd is running on this system
805 if [ ! -f /etc/systemd/system/netdata.service ]
807 echo >&2 "Installing systemd service..."
808 run cp system/netdata.service /etc/systemd/system/netdata.service && \
809 run systemctl daemon-reload && \
810 run systemctl enable netdata
813 install_non_systemd_init
818 # -----------------------------------------------------------------------------
819 # check if we can re-start netdata
826 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
827 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
833 stop_netdata_on_pid() {
834 local pid="${1}" ret=0 count=0
836 isnetdata ${pid} || return 0
838 printf >&2 "Stopping netdata on pid ${pid} ..."
839 while [ ! -z "$pid" -a ${ret} -eq 0 ]
841 if [ ${count} -gt 45 ]
843 echo >&2 "Cannot stop the running netdata on pid ${pid}."
847 count=$(( count + 1 ))
849 run kill ${pid} 2>/dev/null
852 test ${ret} -eq 0 && printf >&2 "." && sleep 2
858 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
862 echo >&2 "netdata on pid ${pid} stopped."
869 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
871 # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
873 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
874 $(cat /var/run/netdata.pid 2>/dev/null) \
875 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
876 $(pidof netdata 2>/dev/null)
878 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
880 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
882 stop_netdata_on_pid ${p}
887 if [ ${DONOTSTART} -eq 1 ]
889 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
891 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
893 if [ "${UID}" -eq 0 ]
895 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
897 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
902 progress "Start netdata"
904 if [ "${UID}" -eq 0 ]
908 service netdata restart && started=1
909 if [ ${started} -eq 0 ]
911 service netdata start && started=1
915 if [ ${started} -eq 0 ]
917 # still not started...
921 echo >&2 "Starting netdata..."
922 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
926 echo >&2 "SORRY! FAILED TO START NETDATA!"
929 echo >&2 "OK. NetData Started!"
935 # -----------------------------------------------------------------------------
936 # save a config file, if it is not already there
938 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
941 echo >&2 "-------------------------------------------------------------------------------"
943 echo >&2 "Downloading default configuration from netdata..."
946 # remove a possibly obsolete download
947 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
949 # disable a proxy to get data from the local netdata
954 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
958 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
960 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
964 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
966 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
967 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
969 if [ "${UID}" -eq 0 ]
971 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
973 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
975 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
976 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
981 # -----------------------------------------------------------------------------
982 progress "Check KSM (kernel memory deduper)"
984 ksm_is_available_but_disabled() {
987 ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
989 You have kernel memory de-duper (called Kernel Same-page Merging,
990 or KSM) available, but it is not currently enabled.
994 ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
995 ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
997 If you enable it, you will save 40-60% of netdata memory.
1002 ksm_is_not_available() {
1005 ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
1007 It seems you do not have kernel memory de-duper (called Kernel Same-page
1008 Merging, or KSM) available.
1010 To enable it, you need a kernel built with CONFIG_KSM=y
1012 If you can have it, you will save 40-60% of netdata memory.
1017 if [ -f "/sys/kernel/mm/ksm/run" ]
1019 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1021 ksm_is_available_but_disabled
1024 ksm_is_not_available
1027 # -----------------------------------------------------------------------------
1028 progress "Check version.txt"
1030 if [ ! -s web/version.txt ]
1034 ${TPUT_BOLD}Version update check warning${TPUT_RESET}
1036 The way you downloaded netdata, we cannot find its version. This means the
1037 Update check on the dashboard, will not work.
1039 If you want to have version update check, please re-install it
1040 following the procedure in:
1042 https://github.com/firehol/netdata/wiki/Installation
1047 # -----------------------------------------------------------------------------
1048 progress "Check apps.plugin"
1050 if [ "${UID}" -ne 0 ]
1052 cat <<SETUID_WARNING
1054 ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
1056 Since you have installed netdata as a normal user, to have apps.plugin collect
1057 all the needed data, you have to give it the access rights it needs, by running
1058 either of the following sets of commands:
1060 To run apps.plugin with escalated capabilities:
1062 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_USER} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1063 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1064 ${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}
1066 or, to run apps.plugin as root:
1068 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1069 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4755 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1071 apps.plugin is performing a hard-coded function of data collection for all
1072 running processes. It cannot be instructed from the netdata daemon to perform
1073 any task, so it is pretty safe to do this.
1078 # -----------------------------------------------------------------------------
1079 progress "Generate netdata-uninstaller.sh"
1081 cat >netdata-uninstaller.sh <<UNINSTALL
1084 # this script will uninstall netdata
1086 if [ "\$1" != "--force" ]
1088 echo >&2 "This script will REMOVE netdata from your system."
1089 echo >&2 "Run it again with --force to do it."
1093 echo >&2 "Stopping a possibly running netdata..."
1094 for p in \$(pidof netdata); do kill \$p; done
1098 if [ ! -z "\$1" -a -d "\$1" ]
1101 echo "Deleting directory '\$1' ..."
1106 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1108 # installation prefix was given
1110 deletedir "${NETDATA_PREFIX}"
1113 # installation prefix was NOT given
1115 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1117 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1118 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1121 deletedir "${NETDATA_PREFIX}/etc/netdata"
1122 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1123 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1124 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1125 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1126 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1129 if [ -f /etc/logrotate.d/netdata ]
1131 echo "Deleting /etc/logrotate.d/netdata ..."
1132 rm -i /etc/logrotate.d/netdata
1135 if [ -f /etc/systemd/system/netdata.service ]
1137 echo "Deleting /etc/systemd/system/netdata.service ..."
1138 rm -i /etc/systemd/system/netdata.service
1141 if [ -f /etc/init.d/netdata ]
1143 echo "Deleting /etc/init.d/netdata ..."
1144 rm -i /etc/init.d/netdata
1147 getent passwd netdata > /dev/null
1151 echo "You may also want to remove the user netdata"
1153 echo " userdel netdata"
1156 getent group netdata > /dev/null
1160 echo "You may also want to remove the group netdata"
1162 echo " groupdel netdata"
1165 getent group docker > /dev/null
1166 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1169 echo "You may also want to remove the netdata user from the docker group"
1171 echo " gpasswd -d netdata docker"
1174 getent group nginx > /dev/null
1175 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1178 echo "You may also want to remove the netdata user from the nginx group"
1180 echo " gpasswd -d netdata nginx"
1183 getent group varnish > /dev/null
1184 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1187 echo "You may also want to remove the netdata user from the varnish group"
1189 echo " gpasswd -d netdata varnish"
1192 getent group haproxy > /dev/null
1193 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1196 echo "You may also want to remove the netdata user from the haproxy group"
1198 echo " gpasswd -d netdata haproxy"
1201 getent group adm > /dev/null
1202 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_ADM}" = "1" ]
1205 echo "You may also want to remove the netdata user from the adm group"
1207 echo " gpasswd -d netdata adm"
1212 chmod 750 netdata-uninstaller.sh
1214 # -----------------------------------------------------------------------------
1215 progress "Basic netdata instructions"
1219 netdata by default listens on all IPs on port ${NETDATA_PORT},
1220 so you can access it with:
1222 ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
1224 To stop netdata, just kill it, with:
1226 ${TPUT_YELLOW}${TPUT_BOLD}killall netdata${TPUT_RESET}
1228 To start it, just run it:
1230 ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
1234 echo >&2 "Uninstall script generated: ${TPUT_RED}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}"
1238 cat >netdata-updater.sh.new <<REINSTALL
1242 [ "\${1}" = "-f" ] && force=1
1244 export PATH="\${PATH}:${PATH}"
1245 export CFLAGS="${CFLAGS}"
1247 INSTALL_UID="${UID}"
1248 if [ "\${INSTALL_UID}" != "\${UID}" ]
1250 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1254 # make sure we cd to the working directory
1255 cd "${REINSTALL_PWD}" || exit 1
1257 # make sure there is .git here
1258 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1260 # signal netdata to start saving its database
1261 # this is handy if your database is big
1262 pids=\$(pidof netdata)
1263 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1268 # we are running on a terminal
1269 # open fd 3 and send it to stderr
1273 # create a temporary file for the log
1274 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1275 # open fd 3 and send it to tmp
1280 echo >&3 "\$(date) : INFO: " "\${@}"
1288 echo >&3 "\$(date) : ERROR: " "\${@}"
1291 # this is what we will do if it fails (head-less only)
1293 error "FAILED TO UPDATE NETDATA : \${1}"
1295 if [ ! -z "\${tmp}" ]
1303 get_latest_commit_id() {
1305 grep ^commit 2>&3 |\\
1307 cut -d ' ' -f 2 2>&3
1311 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1317 info "Updating netdata source from github..."
1319 last_commit="\$(get_latest_commit_id)"
1320 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1322 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1324 new_commit="\$(get_latest_commit_id)"
1325 if [ \${force} -eq 0 ]
1327 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1328 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1330 elif [ \${force} -eq 0 ]
1332 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1336 info "Re-installing netdata..."
1337 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1339 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1343 # the installer updates this script - so we run and exit in a single line
1345 ###############################################################################
1346 ###############################################################################
1348 chmod 755 netdata-updater.sh.new
1349 mv -f netdata-updater.sh.new netdata-updater.sh
1350 echo >&2 "Update script generated : ${TPUT_GREEN}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}"
1352 echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} can work from cron. It will trigger an email from cron"
1353 echo >&2 "only if it fails (it does not print anything if it can update netdata).${TPUT_RESET}"
1354 if [ "${UID}" -eq 0 -a -d "/etc/cron.daily" -a ! -f "/etc/cron.daily/netdata-updater.sh" ]
1356 echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}"
1358 echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}ln -s ${PWD}/netdata-updater.sh /etc/cron.daily/netdata-updater.sh${TPUT_RESET}"
1360 elif [ -f "netdata-updater.sh" ]
1362 rm "netdata-updater.sh"
1365 # -----------------------------------------------------------------------------
1367 progress "We are done!"
1369 if [ ${started} -eq 1 ]
1371 netdata_banner "is installed and running now!"
1373 netdata_banner "is installed now!"
1376 echo >&2 " enjoy real-time performance and health monitoring..."