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}'."
13 # reload the user profile
14 [ -f /etc/profile ] && . /etc/profile
16 # make sure /etc/profile does not change our current directory
17 cd "${netdata_source_dir}" || exit 1
19 # fix PKG_CHECK_MODULES error
20 if [ -d /usr/share/aclocal ]
22 ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
29 # Be nice on production environments
30 renice 19 $$ >/dev/null 2>/dev/null
32 processors=$(grep ^processor </proc/cpuinfo | wc -l)
33 [ $(( processors )) -lt 1 ] && processors=1
35 # you can set CFLAGS before running installer
36 CFLAGS="${CFLAGS--O2}"
37 [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
39 # keep a log of this command
40 printf "\n# " >>netdata-installer.log
41 date >>netdata-installer.log
42 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
43 printf "%q " "$0" "${@}" >>netdata-installer.log
44 printf "\n" >>netdata-installer.log
46 REINSTALL_PWD="${PWD}"
47 REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
51 l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
52 l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
53 l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
55 netdata="netdata" start end msg="${*}"
57 [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
58 [ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
60 start="$(( ${#l2} / 2 - 4 ))"
61 [ $(( start + ${#msg} + 4 )) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
62 end=$(( ${start} + ${#msg} + 4 ))
66 echo >&2 "${l2:0:start}${sp:0:2}${netdata}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}"
67 echo >&2 "${l3:0:start}${sp:0:2}${msg}${sp:0:2}${l3:end:$((${#l2} - end))}"
72 service="$(which service 2>/dev/null || command -v service 2>/dev/null)"
73 systemctl="$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)"
75 local cmd="${1}" action="${2}"
77 if [ ! -z "${service}" ]
79 run "${service}" "${cmd}" "${action}"
81 elif [ ! -z "${systemctl}" ]
83 run "${systemctl}" "${action}" "${cmd}"
96 banner "installer command line options"
99 ${ME} <installer options>
101 Valid <installer options> are:
103 --install /PATH/TO/INSTALL
105 If your give: --install /opt
106 netdata will be installed in /opt/netdata
110 Do not (re)start netdata.
115 Do not wait for the user to press ENTER.
116 Start immediately building it.
118 --zlib-is-really-here
119 --libs-are-really-here
121 If you get errors about missing zlib,
122 or libuuid but you know it is available,
123 you have a broken pkg-config.
124 Use this option to allow it continue
125 without checking pkg-config.
127 Netdata will by default be compiled with gcc optimization -O2
128 If you need to pass different CFLAGS, use something like this:
130 CFLAGS="<gcc options>" ${ME} <installer options>
132 For the installer to complete successfully, you will need
133 these packages installed:
135 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
136 uuid-dev (or libuuid-devel)
138 For the plugins, you will at least need:
145 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null)"
146 get_git_config_signatures() {
149 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
150 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
152 echo >configs.signatures.tmp
154 for x in $(find conf.d -name \*.conf)
158 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
160 git checkout ${c} "conf.d/${x}" || continue
161 s="$(cat "conf.d/${x}" | md5sum | cut -d ' ' -f 1)"
162 echo >>configs.signatures.tmp "${s}:${x}"
165 git checkout HEAD "conf.d/${x}" || break
168 cat configs.signatures.tmp |\
172 echo "declare -A configs_signatures=("
176 echo " ['${md5}']='${file}'"
179 } >configs.signatures
181 rm configs.signatures.tmp
187 while [ ! -z "${1}" ]
189 if [ "$1" = "--install" ]
191 NETDATA_PREFIX="${2}/netdata"
193 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
197 elif [ "$1" = "--dont-start-it" ]
201 elif [ "$1" = "--dont-wait" ]
205 elif [ "$1" = "--help" -o "$1" = "-h" ]
209 elif [ "$1" = "get_git_config_signatures" ]
211 get_git_config_signatures && exit 0
216 echo >&2 "I cannot understand option '$1'."
222 banner "real-time performance monitoring, done right!"
225 You are about to build and install netdata to your system.
227 It will be installed at these locations:
229 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
230 - config files at ${NETDATA_PREFIX}/etc/netdata
231 - web files at ${NETDATA_PREFIX}/usr/share/netdata
232 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
233 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
234 - db files at ${NETDATA_PREFIX}/var/lib/netdata
235 - log files at ${NETDATA_PREFIX}/var/log/netdata
236 - pid file at ${NETDATA_PREFIX}/var/run
238 This installer allows you to change the installation path.
239 Press Control-C and run the same command with --help for help.
243 if [ "${UID}" -ne 0 ]
245 if [ -z "${NETDATA_PREFIX}" ]
247 banner "wrong command line options!"
248 cat <<NONROOTNOPREFIX
250 Sorry! This will fail!
252 You are attempting to install netdata as non-root, but you plan to install it
255 Please set an installation prefix, like this:
257 $0 ${@} --install /tmp
259 or, run the installer as root:
263 We suggest to install it as root, or certain data collectors will not be able
264 to work. Netdata drops root privileges when running. So, if you plan to keep
265 it, install it as root to get the full functionality.
274 You are about to install netdata as a non-root user.
275 Netdata will work, but a few data collection modules that
276 require root access will fail.
278 If you installing permanently on your system, run the
288 if [ "$(type autoreconf 2> /dev/null)" ]
296 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
297 eval $maj=\$1 $min=\$2
299 autoconf_maj_min AMAJ AMIN
304 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
308 echo "Found autotools $AMAJ.$AMIN"
311 echo "No autotools found"
314 if [ ! "$have_autotools" ]
318 echo "Will skip autoreconf step"
320 banner "autotools v2.60 required"
323 -------------------------------------------------------------------------------
324 autotools 2.60 or later is required
326 Sorry, you do not seem to have autotools 2.60 or later, which is
327 required to build from the git sources of netdata.
329 You can either install a suitable version of autotools and automake
330 or download a netdata package which does not have these dependencies.
332 Source packages where autotools have already been run are available
334 https://firehol.org/download/netdata/
336 The unsigned/master folder tracks the head of the git tree and released
337 packages are also available.
343 if [ ${DONOTWAIT} -eq 0 ]
345 if [ ! -z "${NETDATA_PREFIX}" ]
347 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
349 read -p "Press ENTER to build and install netdata to your system > "
354 banner "sorry, it failed to build..."
357 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
359 Sorry! netdata failed to build...
361 You many need to check these:
363 1. The package uuid-dev (or libuuid-devel) has to be installed.
365 If your system cannot find libuuid, although it is installed
366 run me with the option: --libs-are-really-here
368 2. The package zlib1g-dev (or zlib-devel) has to be installed.
370 If your system cannot find zlib, although it is installed
371 run me with the option: --libs-are-really-here
373 3. You need basic build tools installed, like:
375 gcc make autoconf automake pkg-config
377 Autoconf version 2.60 or higher is required.
379 If you still cannot get it to build, ask for help at github:
381 https://github.com/firehol/netdata/issues
390 printf >>netdata-installer.log "# "
391 printf >>netdata-installer.log "%q " "${@}"
392 printf >>netdata-installer.log " ... "
395 printf >&2 ":-----------------------------------------------------------------------------\n"
396 printf >&2 "Running command (in $(pwd)):\n"
398 printf >&2 "%q " "${@}"
406 printf >>netdata-installer.log "FAILED!\n"
408 printf >>netdata-installer.log "OK\n"
414 if [ ${LIBS_ARE_HERE} -eq 1 ]
417 echo >&2 "ok, assuming libs are really installed."
418 export ZLIB_CFLAGS=" "
419 export ZLIB_LIBS="-lz"
420 export UUID_CFLAGS=" "
421 export UUID_LIBS="-luuid"
424 trap build_error EXIT
426 if [ "$have_autotools" ]
428 run ./autogen.sh || exit 1
432 --prefix="${NETDATA_PREFIX}/usr" \
433 --sysconfdir="${NETDATA_PREFIX}/etc" \
434 --localstatedir="${NETDATA_PREFIX}/var" \
435 --with-zlib --with-math --with-user=netdata \
436 CFLAGS="${CFLAGS}" || exit 1
438 # remove the build_error hook
441 if [ -f src/netdata ]
443 echo >&2 "Cleaning a possibly old compilation ..."
447 echo >&2 "Compiling netdata ..."
448 run make -j${processors} || exit 1
450 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
452 declare -A configs_signatures=()
453 if [ -f "configs.signatures" ]
455 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
459 # migrate existing configuration files
460 # for node.d and charts.d
461 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
463 # the configuration directory exists
465 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
467 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
470 # move the charts.d config files
471 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
473 for y in "" ".old" ".orig"
475 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
477 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
482 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
484 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
487 # move the node.d config files
488 for x in named sma_webbox snmp
490 for y in "" ".old" ".orig"
492 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
494 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
500 # backup user configurations
501 installer_backup_suffix="${PID}.${RANDOM}"
502 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
506 # make a backup of the configuration file
507 cp -p "${x}" "${x}.old"
509 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
511 # we don't have md5sum - keep it
512 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
514 # find it relative filename
515 f="${x/*\/etc\/netdata\//}"
518 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
521 if [ -f "conf.d/${f}" ]
523 cp "conf.d/${f}" "${x}.orig"
526 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
528 if [ "${configs_signatures[${md5}]}" = "${f}" ]
530 # it is a stock version - don't keep it
531 echo >&2 "File '${x}' is stock version."
533 # edited by user - keep it
534 echo >&2 "File '${x}' has been edited by user."
535 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
538 echo >&2 "File '${x}' cannot be check for custom edits."
539 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
543 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
545 rm -f "${x}.installer_backup.${installer_backup_suffix}"
549 echo >&2 "Installing netdata ..."
550 run make install || exit 1
552 # restore user configurations
553 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
555 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
557 cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
558 rm -f "${x}.installer_backup.${installer_backup_suffix}"
562 echo >&2 "Fixing permissions ..."
565 which "${1}" >/dev/null 2>&1 && return 0
566 command -v "${1}" >/dev/null 2>&1 && return 0
570 portable_add_user() {
571 local username="${1}"
573 getent passwd "${username}" > /dev/null 2>&1
574 [ $? -eq 0 ] && return 0
576 echo >&2 "Adding ${username} user account ..."
578 local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
583 run useradd -r -g "${username}" -c "${username}" -s "${nologin}" -d / "${username}" && return 0
589 run pw useradd "${username}" -d / -g "${username}" -s "${nologin}" && return 0
595 run adduser -D -G "${username}" "${username}" && return 0
598 echo >&2 "Failed to add ${username} user account !"
603 portable_add_group() {
604 local groupname="${1}"
606 getent group "${groupname}" > /dev/null 2>&1
607 [ $? -eq 0 ] && return 0
609 echo >&2 "Adding ${groupname} user group ..."
612 if check_cmd groupadd
614 run groupadd -r "${groupname}" && return 0
620 run pw groupadd "${groupname}" && return 0
624 if check_cmd addgroup
626 run addgroup "${groupname}" && return 0
629 echo >&2 "Failed to add ${groupname} user group !"
633 portable_add_user_to_group() {
634 local groupname="${1}" username="${2}"
636 getent group "${groupname}" > /dev/null 2>&1
637 [ $? -ne 0 ] && return 1
639 # find the user is already in the group
640 local users=$(getent group "${groupname}" | cut -d ':' -f 4)
641 if [[ ",${users}," =~ ,${username}, ]]
643 # username is already there
646 # username is not in group
647 echo >&2 "Adding ${username} user to the ${groupname} group ..."
652 run usermod -a -G "${groupname}" "${username}" && return 0
658 run pw groupmod "${groupname}" -m "${username}" && return 0
662 if check_cmd addgroup
664 run addgroup "${username}" "${groupname}" && return 0
667 echo >&2 "Failed to add user ${username} to group ${groupname} !"
673 # man systemd-detect-virt
674 local cmd=$(which systemd-detect-virt 2>/dev/null || command -v systemd-detect-virt 2>/dev/null)
675 if [ ! -z "${cmd}" -a -x "${cmd}" ]
677 "${cmd}" --container >/dev/null 2>&1 && return 0
680 # /proc/1/sched exposes the host's pid of our init !
681 # http://stackoverflow.com/a/37016302
682 local pid=$( cat /proc/1/sched | head -n 1 | { IFS='(),#:' read name pid th threads; echo $pid; } )
683 local p=$(( pid + 0 ))
684 [ ${pid} -ne 1 ] && return 0
686 # lxc sets environment variable 'container'
687 [ ! -z "${container}" ] && return 0
689 # docker creates /.dockerenv
690 # http://stackoverflow.com/a/25518345
691 [ -f "/.dockerenv" ] && return 0
693 # ubuntu and debian supply /bin/running-in-container
694 # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
695 if [ -x "/bin/running-in-container" ]
697 "/bin/running-in-container" >/dev/null 2>&1 && return 0
703 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
705 NETDATA_ADDED_TO_DOCKER=0
706 NETDATA_ADDED_TO_NGINX=0
707 NETDATA_ADDED_TO_VARNISH=0
708 NETDATA_ADDED_TO_HAPROXY=0
711 portable_add_group netdata
712 portable_add_user netdata
713 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
714 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
715 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
716 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
718 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
720 echo >&2 "Adding netdata logrotate configuration ..."
721 run cp system/netdata.logrotate /etc/logrotate.d/netdata
724 if [ -f /etc/logrotate.d/netdata ]
726 echo >&2 "Fixing netdata logrotate permissions ..."
727 run chmod 644 /etc/logrotate.d/netdata
732 # -----------------------------------------------------------------------------
733 # load options from the configuration file
735 # create an empty config if it does not exist
736 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
738 # function to extract values from the config file
740 local key="${1}" value="${2}" line=
742 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
744 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
745 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
751 # the user netdata will run as
752 if [ "${UID}" = "0" ]
754 NETDATA_USER="$( config_option "run as user" "netdata" )"
756 NETDATA_USER="${USER}"
759 # the owners of the web files
760 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
761 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
764 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
768 NETDATA_PORT="$( config_option "default port" ${defport} )"
769 NETDATA_PORT2="$( config_option "port" ${defport} )"
771 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
773 if [ "${NETDATA_PORT2}" != "${defport}" ]
775 NETDATA_PORT="${NETDATA_PORT2}"
780 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
781 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
782 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
783 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
784 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
785 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
788 # -----------------------------------------------------------------------------
789 # prepare the directories
791 # this is needed if NETDATA_PREFIX is not empty
792 if [ ! -d "${NETDATA_RUN_DIR}" ]
794 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
798 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
802 for x in "python.d" "charts.d" "node.d"
804 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
806 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
807 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
810 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
811 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
812 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
816 if [ ! -d "${NETDATA_WEB_DIR}" ]
818 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
819 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
821 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
822 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
823 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
827 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
831 echo >&2 "Creating directory '${x}'"
832 run mkdir -p "${x}" || exit 1
835 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
836 #run find "${x}" -type f -exec chmod 0660 {} \;
837 #run find "${x}" -type d -exec chmod 0770 {} \;
840 run chmod 755 "${NETDATA_LOG_DIR}"
846 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
847 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
848 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
849 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
850 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
851 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
856 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
859 if [ ${setcap_ret} -eq 0 ]
861 # if we managed to setcap
862 # but we fail to execute apps.plugin
863 # trigger setuid to root
864 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
869 if [ ${setcap_ret} -ne 0 ]
871 # fix apps.plugin to be setuid to root
872 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
873 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
876 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
877 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
878 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
879 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
882 # --- fix #1292 bug ---
884 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
885 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
888 # -----------------------------------------------------------------------------
889 # check if we can re-start netdata
891 if [ ${DONOTSTART} -eq 1 ]
893 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
895 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
896 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
898 if [ "${UID}" -eq 0 ]
900 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
902 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
904 banner "is installed now!"
905 echo >&2 " enjoy real-time performance and health monitoring..."
909 # -----------------------------------------------------------------------------
910 # stop a running netdata
915 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
916 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
922 stop_netdata_on_pid() {
923 local pid="${1}" ret=0 count=0
925 isnetdata ${pid} || return 0
927 printf >&2 "Stopping netdata on pid ${pid} ..."
928 while [ ! -z "$pid" -a ${ret} -eq 0 ]
930 if [ ${count} -gt 45 ]
932 echo >&2 "Cannot stop the running netdata on pid ${pid}."
936 count=$(( count + 1 ))
938 run kill ${pid} 2>/dev/null
941 test ${ret} -eq 0 && printf >&2 "." && sleep 2
947 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
951 echo >&2 "netdata on pid ${pid} stopped."
958 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
960 echo >&2 "Stopping a (possibly) running netdata..."
962 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
963 $(cat /var/run/netdata.pid 2>/dev/null) \
964 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
965 $(pidof netdata 2>/dev/null)
967 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
969 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
971 stop_netdata_on_pid ${p}
976 # -----------------------------------------------------------------------------
980 local pids p myns ns systemctl
982 # if the directory /etc/systemd/system does not exit, it is not systemd
983 [ ! -d /etc/systemd/system ] && return 1
985 # if there is no systemctl command, it is not systemd
986 systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
987 [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
989 # if pid 1 is systemd, it is systemd
990 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
992 # if systemd is not running, it is not systemd
993 pids=$(pidof systemd 2>/dev/null)
994 [ -z "${pids}" ] && return 1
996 # check if the running systemd processes are not in our namespace
997 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
1000 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
1002 # if pid of systemd is in our namespace, it is systemd
1003 [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
1006 # else, it is not systemd
1011 install_non_systemd_init() {
1012 [ "${UID}" != 0 ] && return 1
1015 if [ -f /etc/os-release ]
1017 source /etc/os-release || return 1
1018 key="${ID}-${VERSION_ID}"
1020 elif [ -f /etc/centos-release ]
1022 key=$(</etc/centos-release)
1025 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
1027 if [ "${key}" = "gentoo" ]
1029 run cp system/netdata-openrc /etc/init.d/netdata && \
1030 run chmod 755 /etc/init.d/netdata && \
1031 run rc-update add netdata default && \
1034 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
1036 run cp system/netdata-lsb /etc/init.d/netdata && \
1037 run chmod 755 /etc/init.d/netdata && \
1038 run update-rc.d netdata defaults && \
1039 run update-rc.d netdata enable && \
1042 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
1044 run cp system/netdata-init-d /etc/init.d/netdata && \
1045 run chmod 755 /etc/init.d/netdata && \
1046 run chkconfig netdata on && \
1055 if [ "${UID}" -eq 0 ]
1060 # systemd is running on this system
1062 if [ ! -f /etc/systemd/system/netdata.service ]
1064 echo >&2 "Installing systemd service..."
1065 run cp system/netdata.service /etc/systemd/system/netdata.service && \
1066 run systemctl daemon-reload && \
1067 run systemctl enable netdata
1069 service netdata stop
1073 service netdata restart && started=1
1075 install_non_systemd_init
1078 if [ ${started} -eq 0 ]
1080 # check if we can use the system service
1081 service netdata stop
1083 service netdata restart && started=1
1084 if [ ${started} -eq 0 ]
1086 service netdata start && started=1
1091 if [ ${started} -eq 0 ]
1093 # still not started...
1097 echo >&2 "Starting netdata..."
1098 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
1102 echo >&2 "SORRY! FAILED TO START NETDATA!"
1105 echo >&2 "OK. NetData Started!"
1111 # -----------------------------------------------------------------------------
1112 # save a config file, if it is not already there
1114 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
1117 echo >&2 "-------------------------------------------------------------------------------"
1119 echo >&2 "Downloading default configuration from netdata..."
1122 # remove a possibly obsolete download
1123 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1125 # disable a proxy to get data from the local netdata
1130 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1134 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1136 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1140 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1142 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1143 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1145 if [ "${UID}" -eq 0 ]
1147 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1149 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1151 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1152 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1156 # -----------------------------------------------------------------------------
1159 ksm_is_available_but_disabled() {
1162 -------------------------------------------------------------------------------
1163 Memory de-duplication instructions
1165 You have kernel memory de-duper (called Kernel Same-page Merging,
1166 or KSM) available, but it is not currently enabled.
1170 echo 1 >/sys/kernel/mm/ksm/run
1171 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
1173 If you enable it, you will save 40-60% of netdata memory.
1178 ksm_is_not_available() {
1181 -------------------------------------------------------------------------------
1182 Memory de-duplication not present in your kernel
1184 It seems you do not have kernel memory de-duper (called Kernel Same-page
1185 Merging, or KSM) available.
1187 To enable it, you need a kernel built with CONFIG_KSM=y
1189 If you can have it, you will save 40-60% of netdata memory.
1194 if [ -f "/sys/kernel/mm/ksm/run" ]
1196 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1198 ksm_is_available_but_disabled
1201 ksm_is_not_available
1204 # -----------------------------------------------------------------------------
1205 # Check for version.txt
1207 if [ ! -s web/version.txt ]
1211 -------------------------------------------------------------------------------
1212 Version update check warning
1214 The way you downloaded netdata, we cannot find its version. This means the
1215 Update check on the dashboard, will not work.
1217 If you want to have version update check, please re-install it
1218 following the procedure in:
1220 https://github.com/firehol/netdata/wiki/Installation
1225 # -----------------------------------------------------------------------------
1226 # apps.plugin warning
1228 if [ "${UID}" -ne 0 ]
1230 cat <<SETUID_WARNING
1232 -------------------------------------------------------------------------------
1233 apps.plugin needs privileges
1235 Since you have installed netdata as a normal user, to have apps.plugin collect
1236 all the needed data, you have to give it the access rights it needs, by running
1237 either of the following sets of commands:
1239 To run apps.plugin with escalated capabilities:
1241 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1242 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1243 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1245 or, to run apps.plugin as root:
1247 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1248 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1250 apps.plugin is performing a hard-coded function of data collection for all
1251 running processes. It cannot be instructed from the netdata daemon to perform
1252 any task, so it is pretty safe to do this.
1257 # -----------------------------------------------------------------------------
1258 # Keep un-install info
1260 cat >netdata-uninstaller.sh <<UNINSTALL
1263 # this script will uninstall netdata
1265 if [ "\$1" != "--force" ]
1267 echo >&2 "This script will REMOVE netdata from your system."
1268 echo >&2 "Run it again with --force to do it."
1272 echo >&2 "Stopping a possibly running netdata..."
1273 for p in \$(pidof netdata); do kill \$p; done
1277 if [ ! -z "\$1" -a -d "\$1" ]
1280 echo "Deleting directory '\$1' ..."
1285 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1287 # installation prefix was given
1289 deletedir "${NETDATA_PREFIX}"
1292 # installation prefix was NOT given
1294 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1296 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1297 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1300 deletedir "${NETDATA_PREFIX}/etc/netdata"
1301 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1302 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1303 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1304 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1305 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1308 if [ -f /etc/logrotate.d/netdata ]
1310 echo "Deleting /etc/logrotate.d/netdata ..."
1311 rm -i /etc/logrotate.d/netdata
1314 if [ -f /etc/systemd/system/netdata.service ]
1316 echo "Deleting /etc/systemd/system/netdata.service ..."
1317 rm -i /etc/systemd/system/netdata.service
1320 if [ -f /etc/init.d/netdata ]
1322 echo "Deleting /etc/init.d/netdata ..."
1323 rm -i /etc/init.d/netdata
1326 getent passwd netdata > /dev/null
1330 echo "You may also want to remove the user netdata"
1332 echo " userdel netdata"
1335 getent group netdata > /dev/null
1339 echo "You may also want to remove the group netdata"
1341 echo " groupdel netdata"
1344 getent group docker > /dev/null
1345 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1348 echo "You may also want to remove the netdata user from the docker group"
1350 echo " gpasswd -d netdata docker"
1353 getent group nginx > /dev/null
1354 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1357 echo "You may also want to remove the netdata user from the nginx group"
1359 echo " gpasswd -d netdata nginx"
1362 getent group varnish > /dev/null
1363 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1366 echo "You may also want to remove the netdata user from the varnish group"
1368 echo " gpasswd -d netdata varnish"
1371 getent group haproxy > /dev/null
1372 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1375 echo "You may also want to remove the netdata user from the haproxy group"
1377 echo " gpasswd -d netdata haproxy"
1382 chmod 750 netdata-uninstaller.sh
1384 # -----------------------------------------------------------------------------
1389 -------------------------------------------------------------------------------
1391 OK. NetData is installed and it is running.
1393 -------------------------------------------------------------------------------
1395 By default netdata listens on all IPs on port ${NETDATA_PORT},
1396 so you can access it with:
1398 http://this.machine.ip:${NETDATA_PORT}/
1400 To stop netdata, just kill it, with:
1404 To start it, just run it:
1406 ${NETDATA_PREFIX}/usr/sbin/netdata
1410 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1414 cat >netdata-updater.sh.new <<REINSTALL
1418 [ "\${1}" = "-f" ] && force=1
1420 export PATH="\${PATH}:${PATH}"
1421 export CFLAGS="${CFLAGS}"
1423 INSTALL_UID="${UID}"
1424 if [ "\${INSTALL_UID}" != "\${UID}" ]
1426 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1430 # make sure we cd to the working directory
1431 cd "${REINSTALL_PWD}" || exit 1
1433 # make sure there is .git here
1434 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1436 # signal netdata to start saving its database
1437 # this is handy if your database is big
1438 pids=\$(pidof netdata)
1439 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1444 # we are running on a terminal
1445 # open fd 3 and send it to stderr
1449 # create a temporary file for the log
1450 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1451 # open fd 3 and send it to tmp
1456 echo >&3 "\$(date) : INFO: " "\${@}"
1464 echo >&3 "\$(date) : ERROR: " "\${@}"
1467 # this is what we will do if it fails (head-less only)
1469 error "FAILED TO UPDATE NETDATA : \${1}"
1471 if [ ! -z "\${tmp}" ]
1479 get_latest_commit_id() {
1481 grep ^commit 2>&3 |\\
1483 cut -d ' ' -f 2 2>&3
1487 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1493 info "Updating netdata source from github..."
1495 last_commit="\$(get_latest_commit_id)"
1496 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1498 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1500 new_commit="\$(get_latest_commit_id)"
1501 if [ \${force} -eq 0 ]
1503 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1504 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1506 elif [ \${force} -eq 0 ]
1508 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1512 info "Re-installing netdata..."
1513 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1515 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1519 # the installer updates this script - so we run and exit in a single line
1521 ###############################################################################
1522 ###############################################################################
1524 chmod 755 netdata-updater.sh.new
1525 mv -f netdata-updater.sh.new netdata-updater.sh
1526 echo >&2 "Update script generated : ./netdata-updater.sh"
1527 elif [ -f "netdata-updater.sh" ]
1529 rm "netdata-updater.sh"
1532 banner "is installed and running now!"
1533 echo >&2 " enjoy real-time performance and health monitoring..."