3 # reload the user profile
4 [ -f /etc/profile ] && . /etc/profile
6 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
8 # fix PKG_CHECK_MODULES error
9 if [ -d /usr/share/aclocal ]
11 ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
18 # Be nice on production environments
19 renice 19 $$ >/dev/null 2>/dev/null
21 processors=$(cat /proc/cpuinfo | grep ^processor | wc -l)
22 [ $(( processors )) -lt 1 ] && processors=1
24 # you can set CFLAGS before running installer
25 CFLAGS="${CFLAGS--O2}"
26 [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
28 # keep a log of this command
29 printf "\n# " >>netdata-installer.log
30 date >>netdata-installer.log
31 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
32 printf "%q " "$0" "${@}" >>netdata-installer.log
33 printf "\n" >>netdata-installer.log
35 REINSTALL_PWD="${PWD}"
36 REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
40 l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
41 l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
42 l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
44 netdata="netdata" start end msg="${*}"
46 [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
47 [ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
49 start="$(( ${#l2} / 2 - 4 ))"
50 [ $(( start + ${#msg} + 4 )) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
51 end=$(( ${start} + ${#msg} + 4 ))
55 echo >&2 "${l2:0:start}${sp:0:2}${netdata}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}"
56 echo >&2 "${l3:0:start}${sp:0:2}${msg}${sp:0:2}${l3:end:$((${#l2} - end))}"
61 service="$(which service 2>/dev/null || command -v service 2>/dev/null)"
62 systemctl="$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)"
64 local cmd="${1}" action="${2}"
66 if [ ! -z "${service}" ]
68 run "${service}" "${cmd}" "${action}"
70 elif [ ! -z "${systemctl}" ]
72 run "${systemctl}" "${action}" "${cmd}"
85 banner "installer command line options"
88 ${ME} <installer options>
90 Valid <installer options> are:
92 --install /PATH/TO/INSTALL
94 If your give: --install /opt
95 netdata will be installed in /opt/netdata
99 Do not (re)start netdata.
104 Do not wait for the user to press ENTER.
105 Start immediately building it.
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)"
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" = "--help" -o "$1" = "-h" ]
198 elif [ "$1" = "get_git_config_signatures" ]
200 get_git_config_signatures && exit 0
205 echo >&2 "I cannot understand option '$1'."
211 banner "real-time performance monitoring, done right!"
214 You are about to build and install netdata to your system.
216 It will be installed at these locations:
218 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
219 - config files at ${NETDATA_PREFIX}/etc/netdata
220 - web files at ${NETDATA_PREFIX}/usr/share/netdata
221 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
222 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
223 - db files at ${NETDATA_PREFIX}/var/lib/netdata
224 - log files at ${NETDATA_PREFIX}/var/log/netdata
225 - pid file at ${NETDATA_PREFIX}/var/run
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 banner "wrong command line options!"
237 cat <<NONROOTNOPREFIX
239 Sorry! This will fail!
241 You are attempting to install netdata as non-root, but you plan to install it
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 not be able
253 to work. Netdata drops root privileges when running. So, if you plan to keep
254 it, install it as root to get the full functionality.
263 You are about to install netdata as a non-root user.
264 Netdata will work, but a few data collection modules that
265 require root access will fail.
267 If you installing permanently on your system, run the
277 if [ "$(type autoreconf 2> /dev/null)" ]
285 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
286 eval $maj=\$1 $min=\$2
288 autoconf_maj_min AMAJ AMIN
293 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
297 echo "Found autotools $AMAJ.$AMIN"
300 echo "No autotools found"
303 if [ ! "$have_autotools" ]
307 echo "Will skip autoreconf step"
309 banner "autotools v2.60 required"
312 -------------------------------------------------------------------------------
313 autotools 2.60 or later is required
315 Sorry, you do not seem to have autotools 2.60 or later, which is
316 required to build from the git sources of netdata.
318 You can either install a suitable version of autotools and automake
319 or download a netdata package which does not have these dependencies.
321 Source packages where autotools have already been run are available
323 https://firehol.org/download/netdata/
325 The unsigned/master folder tracks the head of the git tree and released
326 packages are also available.
332 if [ ${DONOTWAIT} -eq 0 ]
334 if [ ! -z "${NETDATA_PREFIX}" ]
336 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
338 read -p "Press ENTER to build and install netdata to your system > "
343 banner "sorry, it failed to build..."
346 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
348 Sorry! netdata failed to build...
350 You many need to check these:
352 1. The package uuid-dev (or libuuid-devel) has to be installed.
354 If your system cannot find libuuid, although it is installed
355 run me with the option: --libs-are-really-here
357 2. The package zlib1g-dev (or zlib-devel) has to be installed.
359 If your system cannot find zlib, although it is installed
360 run me with the option: --libs-are-really-here
362 3. You need basic build tools installed, like:
364 gcc make autoconf automake pkg-config
366 Autoconf version 2.60 or higher is required.
368 If you still cannot get it to build, ask for help at github:
370 https://github.com/firehol/netdata/issues
379 printf >>netdata-installer.log "# "
380 printf >>netdata-installer.log "%q " "${@}"
381 printf >>netdata-installer.log " ... "
384 printf >&2 ":-----------------------------------------------------------------------------\n"
385 printf >&2 "Running command:\n"
387 printf >&2 "%q " "${@}"
395 printf >>netdata-installer.log "FAILED!\n"
397 printf >>netdata-installer.log "OK\n"
403 if [ ${LIBS_ARE_HERE} -eq 1 ]
406 echo >&2 "ok, assuming libs are really installed."
407 export ZLIB_CFLAGS=" "
408 export ZLIB_LIBS="-lz"
409 export UUID_CFLAGS=" "
410 export UUID_LIBS="-luuid"
413 trap build_error EXIT
415 if [ "$have_autotools" ]
417 run ./autogen.sh || exit 1
421 --prefix="${NETDATA_PREFIX}/usr" \
422 --sysconfdir="${NETDATA_PREFIX}/etc" \
423 --localstatedir="${NETDATA_PREFIX}/var" \
424 --with-zlib --with-math --with-user=netdata \
425 CFLAGS="${CFLAGS}" || exit 1
427 # remove the build_error hook
430 if [ -f src/netdata ]
432 echo >&2 "Cleaning a possibly old compilation ..."
436 echo >&2 "Compiling netdata ..."
437 run make -j${processors} || exit 1
439 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
441 declare -A configs_signatures=()
442 if [ -f "configs.signatures" ]
444 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
448 # migrate existing configuration files
449 # for node.d and charts.d
450 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
452 # the configuration directory exists
454 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
456 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
459 # move the charts.d config files
460 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
462 for y in "" ".old" ".orig"
464 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
466 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
471 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
473 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
476 # move the node.d config files
477 for x in named sma_webbox snmp
479 for y in "" ".old" ".orig"
481 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
483 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
489 # backup user configurations
490 installer_backup_suffix="${PID}.${RANDOM}"
491 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
495 # make a backup of the configuration file
496 cp -p "${x}" "${x}.old"
498 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
500 # we don't have md5sum - keep it
501 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
503 # find it relative filename
504 f="${x/*\/etc\/netdata\//}"
507 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
510 if [ -f "conf.d/${f}" ]
512 cp "conf.d/${f}" "${x}.orig"
515 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
517 if [ "${configs_signatures[${md5}]}" = "${f}" ]
519 # it is a stock version - don't keep it
520 echo >&2 "File '${x}' is stock version."
522 # edited by user - keep it
523 echo >&2 "File '${x}' has been edited by user."
524 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
527 echo >&2 "File '${x}' cannot be check for custom edits."
528 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
532 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
534 rm -f "${x}.installer_backup.${installer_backup_suffix}"
538 echo >&2 "Installing netdata ..."
539 run make install || exit 1
541 # restore user configurations
542 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
544 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
546 cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
547 rm -f "${x}.installer_backup.${installer_backup_suffix}"
551 echo >&2 "Fixing permissions ..."
554 which "${1}" >/dev/null 2>&1 && return 0
555 command -v "${1}" >/dev/null 2>&1 && return 0
559 portable_add_user() {
560 local username="${1}"
562 getent passwd "${username}" > /dev/null 2>&1
563 [ $? -eq 0 ] && return 0
565 echo >&2 "Adding ${username} user account ..."
567 local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
572 run useradd -r -g "${username}" -c "${username}" -s "${nologin}" -d / "${username}" && return 0
578 run pw useradd "${username}" -d / -g "${username}" -s "${nologin}" && return 0
584 run adduser -D -G "${username}" "${username}" && return 0
587 echo >&2 "Failed to add ${username} user account !"
592 portable_add_group() {
593 local groupname="${1}"
595 getent group "${groupname}" > /dev/null 2>&1
596 [ $? -eq 0 ] && return 0
598 echo >&2 "Adding ${groupname} user group ..."
601 if check_cmd groupadd
603 run groupadd -r "${groupname}" && return 0
609 run pw groupadd "${groupname}" && return 0
613 if check_cmd addgroup
615 run addgroup "${groupname}" && return 0
618 echo >&2 "Failed to add ${groupname} user group !"
622 portable_add_user_to_group() {
623 local groupname="${1}" username="${2}"
625 getent group "${groupname}" > /dev/null 2>&1
626 [ $? -ne 0 ] && return 1
628 # find the user is already in the group
629 local users=$(getent group "${groupname}" | cut -d ':' -f 4)
630 if [[ ",${users}," =~ ,${username}, ]]
632 # username is already there
635 # username is not in group
636 echo >&2 "Adding ${username} user to the ${groupname} group ..."
641 run usermod -a -G "${groupname}" "${username}" && return 0
647 run pw groupmod "${groupname}" -m "${username}" && return 0
651 if check_cmd addgroup
653 run addgroup "${username}" "${groupname}" && return 0
656 echo >&2 "Failed to add user ${username} to group ${groupname} !"
662 # man systemd-detect-virt
663 local cmd=$(which systemd-detect-virt 2>/dev/null || command -v systemd-detect-virt 2>/dev/null)
664 if [ ! -z "${cmd}" -a -x "${cmd}" ]
666 "${cmd}" --container >/dev/null 2>&1 && return 0
669 # /proc/1/sched exposes the host's pid of our init !
670 # http://stackoverflow.com/a/37016302
671 local pid=$( cat /proc/1/sched | head -n 1 | { IFS='(),#:' read name pid th threads; echo $pid; } )
672 local p=$(( pid + 0 ))
673 [ ${pid} -ne 1 ] && return 0
675 # lxc sets environment variable 'container'
676 [ ! -z "${container}" ] && return 0
678 # docker creates /.dockerenv
679 # http://stackoverflow.com/a/25518345
680 [ -f "/.dockerenv" ] && return 0
682 # ubuntu and debian supply /bin/running-in-container
683 # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
684 if [ -x "/bin/running-in-container" ]
686 "/bin/running-in-container" >/dev/null 2>&1 && return 0
692 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
694 NETDATA_ADDED_TO_DOCKER=0
695 NETDATA_ADDED_TO_NGINX=0
696 NETDATA_ADDED_TO_VARNISH=0
697 NETDATA_ADDED_TO_HAPROXY=0
700 portable_add_group netdata
701 portable_add_user netdata
702 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
703 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
704 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
705 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
707 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
709 echo >&2 "Adding netdata logrotate configuration ..."
710 run cp system/netdata.logrotate /etc/logrotate.d/netdata
713 if [ -f /etc/logrotate.d/netdata ]
715 echo >&2 "Fixing netdata logrotate permissions ..."
716 run chmod 644 /etc/logrotate.d/netdata
721 # -----------------------------------------------------------------------------
722 # load options from the configuration file
724 # create an empty config if it does not exist
725 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
727 # function to extract values from the config file
729 local key="${1}" value="${2}" line=
731 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
733 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
734 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
740 # the user netdata will run as
741 if [ "${UID}" = "0" ]
743 NETDATA_USER="$( config_option "run as user" "netdata" )"
745 NETDATA_USER="${USER}"
748 # the owners of the web files
749 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
750 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
753 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
757 NETDATA_PORT="$( config_option "default port" ${defport} )"
758 NETDATA_PORT2="$( config_option "port" ${defport} )"
760 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
762 if [ "${NETDATA_PORT2}" != "${defport}" ]
764 NETDATA_PORT="${NETDATA_PORT2}"
769 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
770 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
771 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
772 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
773 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
774 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
777 # -----------------------------------------------------------------------------
778 # prepare the directories
780 # this is needed if NETDATA_PREFIX is not empty
781 if [ ! -d "${NETDATA_RUN_DIR}" ]
783 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
787 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
791 for x in "python.d" "charts.d" "node.d"
793 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
795 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
796 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
799 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
800 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
801 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
805 if [ ! -d "${NETDATA_WEB_DIR}" ]
807 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
808 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
810 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
811 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
812 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
816 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
820 echo >&2 "Creating directory '${x}'"
821 run mkdir -p "${x}" || exit 1
824 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
825 #run find "${x}" -type f -exec chmod 0660 {} \;
826 #run find "${x}" -type d -exec chmod 0770 {} \;
829 run chmod 755 "${NETDATA_LOG_DIR}"
835 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
836 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
837 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
838 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
839 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
840 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
845 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
848 if [ ${setcap_ret} -eq 0 ]
850 # if we managed to setcap
851 # but we fail to execute apps.plugin
852 # trigger setuid to root
853 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
858 if [ ${setcap_ret} -ne 0 ]
860 # fix apps.plugin to be setuid to root
861 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
862 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
865 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
866 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
867 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
868 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
871 # --- fix #1292 bug ---
873 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
874 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
877 # -----------------------------------------------------------------------------
878 # check if we can re-start netdata
880 if [ ${DONOTSTART} -eq 1 ]
882 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
884 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
885 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
887 if [ "${UID}" -eq 0 ]
889 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
891 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
893 banner "is installed now!"
894 echo >&2 " enjoy real-time performance and health monitoring..."
898 # -----------------------------------------------------------------------------
899 # stop a running netdata
904 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
905 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
911 stop_netdata_on_pid() {
912 local pid="${1}" ret=0 count=0
914 isnetdata ${pid} || return 0
916 printf >&2 "Stopping netdata on pid ${pid} ..."
917 while [ ! -z "$pid" -a ${ret} -eq 0 ]
919 if [ ${count} -gt 45 ]
921 echo >&2 "Cannot stop the running netdata on pid ${pid}."
925 count=$(( count + 1 ))
927 run kill ${pid} 2>/dev/null
930 test ${ret} -eq 0 && printf >&2 "." && sleep 2
936 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
940 echo >&2 "netdata on pid ${pid} stopped."
947 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
949 echo >&2 "Stopping a (possibly) running netdata..."
951 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
952 $(cat /var/run/netdata.pid 2>/dev/null) \
953 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
954 $(pidof netdata 2>/dev/null)
956 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
958 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
960 stop_netdata_on_pid ${p}
965 # -----------------------------------------------------------------------------
969 local pids p myns ns systemctl
971 # if the directory /etc/systemd/system does not exit, it is not systemd
972 [ ! -d /etc/systemd/system ] && return 1
974 # if there is no systemctl command, it is not systemd
975 systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
976 [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
978 # if pid 1 is systemd, it is systemd
979 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
981 # if systemd is not running, it is not systemd
982 pids=$(pidof systemd 2>/dev/null)
983 [ -z "${pids}" ] && return 1
985 # check if the running systemd processes are not in our namespace
986 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
989 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
991 # if pid of systemd is in our namespace, it is systemd
992 [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
995 # else, it is not systemd
1000 install_non_systemd_init() {
1001 [ "${UID}" != 0 ] && return 1
1004 if [ -f /etc/os-release ]
1006 source /etc/os-release || return 1
1007 key="${ID}-${VERSION_ID}"
1009 elif [ -f /etc/centos-release ]
1011 key=$(</etc/centos-release)
1014 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
1016 if [ "${key}" = "gentoo" ]
1018 run cp system/netdata-openrc /etc/init.d/netdata && \
1019 run chmod 755 /etc/init.d/netdata && \
1020 run rc-update add netdata default && \
1023 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
1025 run cp system/netdata-lsb /etc/init.d/netdata && \
1026 run chmod 755 /etc/init.d/netdata && \
1027 run update-rc.d netdata defaults && \
1028 run update-rc.d netdata enable && \
1031 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
1033 run cp system/netdata-init-d /etc/init.d/netdata && \
1034 run chmod 755 /etc/init.d/netdata && \
1035 run chkconfig netdata on && \
1044 if [ "${UID}" -eq 0 ]
1049 # systemd is running on this system
1051 if [ ! -f /etc/systemd/system/netdata.service ]
1053 echo >&2 "Installing systemd service..."
1054 run cp system/netdata.service /etc/systemd/system/netdata.service && \
1055 run systemctl daemon-reload && \
1056 run systemctl enable netdata
1058 service netdata stop
1062 service netdata restart && started=1
1064 install_non_systemd_init
1067 if [ ${started} -eq 0 ]
1069 # check if we can use the system service
1070 service netdata stop
1072 service netdata restart && started=1
1073 if [ ${started} -eq 0 ]
1075 service netdata start && started=1
1080 if [ ${started} -eq 0 ]
1082 # still not started...
1086 echo >&2 "Starting netdata..."
1087 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
1091 echo >&2 "SORRY! FAILED TO START NETDATA!"
1094 echo >&2 "OK. NetData Started!"
1100 # -----------------------------------------------------------------------------
1101 # save a config file, if it is not already there
1103 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
1106 echo >&2 "-------------------------------------------------------------------------------"
1108 echo >&2 "Downloading default configuration from netdata..."
1111 # remove a possibly obsolete download
1112 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1114 # disable a proxy to get data from the local netdata
1119 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1123 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1125 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1129 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1131 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1132 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1134 if [ "${UID}" -eq 0 ]
1136 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1138 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1140 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1141 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1145 # -----------------------------------------------------------------------------
1148 ksm_is_available_but_disabled() {
1151 -------------------------------------------------------------------------------
1152 Memory de-duplication instructions
1154 You have kernel memory de-duper (called Kernel Same-page Merging,
1155 or KSM) available, but it is not currently enabled.
1159 echo 1 >/sys/kernel/mm/ksm/run
1160 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
1162 If you enable it, you will save 40-60% of netdata memory.
1167 ksm_is_not_available() {
1170 -------------------------------------------------------------------------------
1171 Memory de-duplication not present in your kernel
1173 It seems you do not have kernel memory de-duper (called Kernel Same-page
1174 Merging, or KSM) available.
1176 To enable it, you need a kernel built with CONFIG_KSM=y
1178 If you can have it, you will save 40-60% of netdata memory.
1183 if [ -f "/sys/kernel/mm/ksm/run" ]
1185 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1187 ksm_is_available_but_disabled
1190 ksm_is_not_available
1193 # -----------------------------------------------------------------------------
1194 # Check for version.txt
1196 if [ ! -s web/version.txt ]
1200 -------------------------------------------------------------------------------
1201 Version update check warning
1203 The way you downloaded netdata, we cannot find its version. This means the
1204 Update check on the dashboard, will not work.
1206 If you want to have version update check, please re-install it
1207 following the procedure in:
1209 https://github.com/firehol/netdata/wiki/Installation
1214 # -----------------------------------------------------------------------------
1215 # apps.plugin warning
1217 if [ "${UID}" -ne 0 ]
1219 cat <<SETUID_WARNING
1221 -------------------------------------------------------------------------------
1222 apps.plugin needs privileges
1224 Since you have installed netdata as a normal user, to have apps.plugin collect
1225 all the needed data, you have to give it the access rights it needs, by running
1226 either of the following sets of commands:
1228 To run apps.plugin with escalated capabilities:
1230 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1231 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1232 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1234 or, to run apps.plugin as root:
1236 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1237 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1239 apps.plugin is performing a hard-coded function of data collection for all
1240 running processes. It cannot be instructed from the netdata daemon to perform
1241 any task, so it is pretty safe to do this.
1246 # -----------------------------------------------------------------------------
1247 # Keep un-install info
1249 cat >netdata-uninstaller.sh <<UNINSTALL
1252 # this script will uninstall netdata
1254 if [ "\$1" != "--force" ]
1256 echo >&2 "This script will REMOVE netdata from your system."
1257 echo >&2 "Run it again with --force to do it."
1261 echo >&2 "Stopping a possibly running netdata..."
1262 for p in \$(pidof netdata); do kill \$p; done
1266 if [ ! -z "\$1" -a -d "\$1" ]
1269 echo "Deleting directory '\$1' ..."
1274 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1276 # installation prefix was given
1278 deletedir "${NETDATA_PREFIX}"
1281 # installation prefix was NOT given
1283 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1285 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1286 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1289 deletedir "${NETDATA_PREFIX}/etc/netdata"
1290 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1291 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1292 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1293 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1294 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1297 if [ -f /etc/logrotate.d/netdata ]
1299 echo "Deleting /etc/logrotate.d/netdata ..."
1300 rm -i /etc/logrotate.d/netdata
1303 if [ -f /etc/systemd/system/netdata.service ]
1305 echo "Deleting /etc/systemd/system/netdata.service ..."
1306 rm -i /etc/systemd/system/netdata.service
1309 if [ -f /etc/init.d/netdata ]
1311 echo "Deleting /etc/init.d/netdata ..."
1312 rm -i /etc/init.d/netdata
1315 getent passwd netdata > /dev/null
1319 echo "You may also want to remove the user netdata"
1321 echo " userdel netdata"
1324 getent group netdata > /dev/null
1328 echo "You may also want to remove the group netdata"
1330 echo " groupdel netdata"
1333 getent group docker > /dev/null
1334 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1337 echo "You may also want to remove the netdata user from the docker group"
1339 echo " gpasswd -d netdata docker"
1342 getent group nginx > /dev/null
1343 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1346 echo "You may also want to remove the netdata user from the nginx group"
1348 echo " gpasswd -d netdata nginx"
1351 getent group varnish > /dev/null
1352 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1355 echo "You may also want to remove the netdata user from the varnish group"
1357 echo " gpasswd -d netdata varnish"
1360 getent group haproxy > /dev/null
1361 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1364 echo "You may also want to remove the netdata user from the haproxy group"
1366 echo " gpasswd -d netdata haproxy"
1371 chmod 750 netdata-uninstaller.sh
1373 # -----------------------------------------------------------------------------
1378 -------------------------------------------------------------------------------
1380 OK. NetData is installed and it is running.
1382 -------------------------------------------------------------------------------
1384 By default netdata listens on all IPs on port ${NETDATA_PORT},
1385 so you can access it with:
1387 http://this.machine.ip:${NETDATA_PORT}/
1389 To stop netdata, just kill it, with:
1393 To start it, just run it:
1395 ${NETDATA_PREFIX}/usr/sbin/netdata
1399 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1403 cat >netdata-updater.sh.new <<REINSTALL
1407 [ "\${1}" = "-f" ] && force=1
1409 export PATH="\${PATH}:${PATH}"
1410 export CFLAGS="${CFLAGS}"
1412 INSTALL_UID="${UID}"
1413 if [ "\${INSTALL_UID}" != "\${UID}" ]
1415 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1419 # make sure we cd to the working directory
1420 cd "${REINSTALL_PWD}" || exit 1
1422 # make sure there is .git here
1423 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1425 # signal netdata to start saving its database
1426 # this is handy if your database is big
1427 pids=\$(pidof netdata)
1428 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1433 # we are running on a terminal
1434 # open fd 3 and send it to stderr
1438 # create a temporary file for the log
1439 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1440 # open fd 3 and send it to tmp
1445 echo >&3 "\$(date) : INFO: " "\${@}"
1453 echo >&3 "\$(date) : ERROR: " "\${@}"
1456 # this is what we will do if it fails (head-less only)
1458 error "FAILED TO UPDATE NETDATA : \${1}"
1460 if [ ! -z "\${tmp}" ]
1468 get_latest_commit_id() {
1470 grep ^commit 2>&3 |\\
1472 cut -d ' ' -f 2 2>&3
1476 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1482 info "Updating netdata source from github..."
1484 last_commit="\$(get_latest_commit_id)"
1485 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1487 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1489 new_commit="\$(get_latest_commit_id)"
1490 if [ \${force} -eq 0 ]
1492 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1493 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1495 elif [ \${force} -eq 0 ]
1497 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1501 info "Re-installing netdata..."
1502 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1504 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1508 # the installer updates this script - so we run and exit in a single line
1510 ###############################################################################
1511 ###############################################################################
1513 chmod 755 netdata-updater.sh.new
1514 mv -f netdata-updater.sh.new netdata-updater.sh
1515 echo >&2 "Update script generated : ./netdata-updater.sh"
1516 elif [ -f "netdata-updater.sh" ]
1518 rm "netdata-updater.sh"
1521 banner "is installed and running now!"
1522 echo >&2 " enjoy real-time performance and health monitoring..."