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
699 portable_add_group netdata
700 portable_add_user netdata
701 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
702 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
703 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
705 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
707 echo >&2 "Adding netdata logrotate configuration ..."
708 run cp system/netdata.logrotate /etc/logrotate.d/netdata
711 if [ -f /etc/logrotate.d/netdata ]
713 echo >&2 "Fixing netdata logrotate permissions ..."
714 run chmod 644 /etc/logrotate.d/netdata
719 # -----------------------------------------------------------------------------
720 # load options from the configuration file
722 # create an empty config if it does not exist
723 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
725 # function to extract values from the config file
727 local key="${1}" value="${2}" line=
729 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
731 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
732 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
738 # the user netdata will run as
739 if [ "${UID}" = "0" ]
741 NETDATA_USER="$( config_option "run as user" "netdata" )"
743 NETDATA_USER="${USER}"
746 # the owners of the web files
747 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
748 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
751 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
755 NETDATA_PORT="$( config_option "default port" ${defport} )"
756 NETDATA_PORT2="$( config_option "port" ${defport} )"
758 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
760 if [ "${NETDATA_PORT2}" != "${defport}" ]
762 NETDATA_PORT="${NETDATA_PORT2}"
767 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
768 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
769 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
770 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
771 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
772 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
775 # -----------------------------------------------------------------------------
776 # prepare the directories
778 # this is needed if NETDATA_PREFIX is not empty
779 if [ ! -d "${NETDATA_RUN_DIR}" ]
781 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
785 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
789 for x in "python.d" "charts.d" "node.d"
791 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
793 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
794 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
797 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
798 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
799 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
803 if [ ! -d "${NETDATA_WEB_DIR}" ]
805 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
806 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
808 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
809 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
810 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
814 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
818 echo >&2 "Creating directory '${x}'"
819 run mkdir -p "${x}" || exit 1
822 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
823 #run find "${x}" -type f -exec chmod 0660 {} \;
824 #run find "${x}" -type d -exec chmod 0770 {} \;
827 run chmod 755 "${NETDATA_LOG_DIR}"
833 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
834 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
835 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
836 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
837 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
838 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
843 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
846 if [ ${setcap_ret} -eq 0 ]
848 # if we managed to setcap
849 # but we fail to execute apps.plugin
850 # trigger setuid to root
851 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
856 if [ ${setcap_ret} -ne 0 ]
858 # fix apps.plugin to be setuid to root
859 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
860 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
863 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
864 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
865 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
866 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
869 # --- fix #1292 bug ---
871 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
872 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
875 # -----------------------------------------------------------------------------
876 # check if we can re-start netdata
878 if [ ${DONOTSTART} -eq 1 ]
880 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
882 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
883 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
885 if [ "${UID}" -eq 0 ]
887 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
889 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
891 banner "is installed now!"
892 echo >&2 " enjoy real-time performance and health monitoring..."
896 # -----------------------------------------------------------------------------
897 # stop a running netdata
902 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
903 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
909 stop_netdata_on_pid() {
910 local pid="${1}" ret=0 count=0
912 isnetdata ${pid} || return 0
914 printf >&2 "Stopping netdata on pid ${pid} ..."
915 while [ ! -z "$pid" -a ${ret} -eq 0 ]
917 if [ ${count} -gt 45 ]
919 echo >&2 "Cannot stop the running netdata on pid ${pid}."
923 count=$(( count + 1 ))
925 run kill ${pid} 2>/dev/null
928 test ${ret} -eq 0 && printf >&2 "." && sleep 2
934 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
938 echo >&2 "netdata on pid ${pid} stopped."
945 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
947 echo >&2 "Stopping a (possibly) running netdata..."
949 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
950 $(cat /var/run/netdata.pid 2>/dev/null) \
951 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
952 $(pidof netdata 2>/dev/null)
954 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
956 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
958 stop_netdata_on_pid ${p}
963 # -----------------------------------------------------------------------------
967 local pids p myns ns systemctl
969 # if the directory /etc/systemd/system does not exit, it is not systemd
970 [ ! -d /etc/systemd/system ] && return 1
972 # if there is no systemctl command, it is not systemd
973 systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
974 [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
976 # if pid 1 is systemd, it is systemd
977 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
979 # if systemd is not running, it is not systemd
980 pids=$(pidof systemd 2>/dev/null)
981 [ -z "${pids}" ] && return 1
983 # check if the running systemd processes are not in our namespace
984 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
987 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
989 # if pid of systemd is in our namespace, it is systemd
990 [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
993 # else, it is not systemd
998 install_non_systemd_init() {
999 [ "${UID}" != 0 ] && return 1
1002 if [ -f /etc/os-release ]
1004 source /etc/os-release || return 1
1005 key="${ID}-${VERSION_ID}"
1007 elif [ -f /etc/centos-release ]
1009 key=$(</etc/centos-release)
1012 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
1014 if [ "${key}" = "gentoo" ]
1016 run cp system/netdata-openrc /etc/init.d/netdata && \
1017 run chmod 755 /etc/init.d/netdata && \
1018 run rc-update add netdata default && \
1021 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
1023 run cp system/netdata-lsb /etc/init.d/netdata && \
1024 run chmod 755 /etc/init.d/netdata && \
1025 run update-rc.d netdata defaults && \
1026 run update-rc.d netdata enable && \
1029 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
1031 run cp system/netdata-init-d /etc/init.d/netdata && \
1032 run chmod 755 /etc/init.d/netdata && \
1033 run chkconfig netdata on && \
1042 if [ "${UID}" -eq 0 ]
1047 # systemd is running on this system
1049 if [ ! -f /etc/systemd/system/netdata.service ]
1051 echo >&2 "Installing systemd service..."
1052 run cp system/netdata.service /etc/systemd/system/netdata.service && \
1053 run systemctl daemon-reload && \
1054 run systemctl enable netdata
1056 service netdata stop
1060 service netdata restart && started=1
1062 install_non_systemd_init
1065 if [ ${started} -eq 0 ]
1067 # check if we can use the system service
1068 service netdata stop
1070 service netdata restart && started=1
1071 if [ ${started} -eq 0 ]
1073 service netdata start && started=1
1078 if [ ${started} -eq 0 ]
1080 # still not started...
1084 echo >&2 "Starting netdata..."
1085 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
1089 echo >&2 "SORRY! FAILED TO START NETDATA!"
1092 echo >&2 "OK. NetData Started!"
1098 # -----------------------------------------------------------------------------
1099 # save a config file, if it is not already there
1101 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
1104 echo >&2 "-------------------------------------------------------------------------------"
1106 echo >&2 "Downloading default configuration from netdata..."
1109 # remove a possibly obsolete download
1110 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1112 # disable a proxy to get data from the local netdata
1117 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1121 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1123 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1127 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1129 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1130 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1132 if [ "${UID}" -eq 0 ]
1134 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1136 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1138 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1139 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1143 # -----------------------------------------------------------------------------
1146 ksm_is_available_but_disabled() {
1149 -------------------------------------------------------------------------------
1150 Memory de-duplication instructions
1152 You have kernel memory de-duper (called Kernel Same-page Merging,
1153 or KSM) available, but it is not currently enabled.
1157 echo 1 >/sys/kernel/mm/ksm/run
1158 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
1160 If you enable it, you will save 40-60% of netdata memory.
1165 ksm_is_not_available() {
1168 -------------------------------------------------------------------------------
1169 Memory de-duplication not present in your kernel
1171 It seems you do not have kernel memory de-duper (called Kernel Same-page
1172 Merging, or KSM) available.
1174 To enable it, you need a kernel built with CONFIG_KSM=y
1176 If you can have it, you will save 40-60% of netdata memory.
1181 if [ -f "/sys/kernel/mm/ksm/run" ]
1183 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1185 ksm_is_available_but_disabled
1188 ksm_is_not_available
1191 # -----------------------------------------------------------------------------
1192 # Check for version.txt
1194 if [ ! -s web/version.txt ]
1198 -------------------------------------------------------------------------------
1199 Version update check warning
1201 The way you downloaded netdata, we cannot find its version. This means the
1202 Update check on the dashboard, will not work.
1204 If you want to have version update check, please re-install it
1205 following the procedure in:
1207 https://github.com/firehol/netdata/wiki/Installation
1212 # -----------------------------------------------------------------------------
1213 # apps.plugin warning
1215 if [ "${UID}" -ne 0 ]
1217 cat <<SETUID_WARNING
1219 -------------------------------------------------------------------------------
1220 apps.plugin needs privileges
1222 Since you have installed netdata as a normal user, to have apps.plugin collect
1223 all the needed data, you have to give it the access rights it needs, by running
1224 either of the following sets of commands:
1226 To run apps.plugin with escalated capabilities:
1228 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1229 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1230 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1232 or, to run apps.plugin as root:
1234 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1235 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1237 apps.plugin is performing a hard-coded function of data collection for all
1238 running processes. It cannot be instructed from the netdata daemon to perform
1239 any task, so it is pretty safe to do this.
1244 # -----------------------------------------------------------------------------
1245 # Keep un-install info
1247 cat >netdata-uninstaller.sh <<UNINSTALL
1250 # this script will uninstall netdata
1252 if [ "\$1" != "--force" ]
1254 echo >&2 "This script will REMOVE netdata from your system."
1255 echo >&2 "Run it again with --force to do it."
1259 echo >&2 "Stopping a possibly running netdata..."
1260 for p in \$(pidof netdata); do kill \$p; done
1264 if [ ! -z "\$1" -a -d "\$1" ]
1267 echo "Deleting directory '\$1' ..."
1272 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1274 # installation prefix was given
1276 deletedir "${NETDATA_PREFIX}"
1279 # installation prefix was NOT given
1281 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1283 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1284 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1287 deletedir "${NETDATA_PREFIX}/etc/netdata"
1288 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1289 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1290 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1291 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1292 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1295 if [ -f /etc/logrotate.d/netdata ]
1297 echo "Deleting /etc/logrotate.d/netdata ..."
1298 rm -i /etc/logrotate.d/netdata
1301 if [ -f /etc/systemd/system/netdata.service ]
1303 echo "Deleting /etc/systemd/system/netdata.service ..."
1304 rm -i /etc/systemd/system/netdata.service
1307 if [ -f /etc/init.d/netdata ]
1309 echo "Deleting /etc/init.d/netdata ..."
1310 rm -i /etc/init.d/netdata
1313 getent passwd netdata > /dev/null
1317 echo "You may also want to remove the user netdata"
1319 echo " userdel netdata"
1322 getent group netdata > /dev/null
1326 echo "You may also want to remove the group netdata"
1328 echo " groupdel netdata"
1331 getent group docker > /dev/null
1332 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1335 echo "You may also want to remove the netdata user from the docker group"
1337 echo " gpasswd -d netdata docker"
1340 getent group nginx > /dev/null
1341 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1344 echo "You may also want to remove the netdata user from the nginx group"
1346 echo " gpasswd -d netdata nginx"
1349 getent group varnish > /dev/null
1350 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1353 echo "You may also want to remove the netdata user from the varnish group"
1355 echo " gpasswd -d netdata varnish"
1359 chmod 750 netdata-uninstaller.sh
1361 # -----------------------------------------------------------------------------
1366 -------------------------------------------------------------------------------
1368 OK. NetData is installed and it is running.
1370 -------------------------------------------------------------------------------
1372 By default netdata listens on all IPs on port ${NETDATA_PORT},
1373 so you can access it with:
1375 http://this.machine.ip:${NETDATA_PORT}/
1377 To stop netdata, just kill it, with:
1381 To start it, just run it:
1383 ${NETDATA_PREFIX}/usr/sbin/netdata
1387 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1391 cat >netdata-updater.sh.new <<REINSTALL
1395 [ "\${1}" = "-f" ] && force=1
1397 export PATH="\${PATH}:${PATH}"
1398 export CFLAGS="${CFLAGS}"
1400 INSTALL_UID="${UID}"
1401 if [ "\${INSTALL_UID}" != "\${UID}" ]
1403 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1407 # make sure we cd to the working directory
1408 cd "${REINSTALL_PWD}" || exit 1
1410 # make sure there is .git here
1411 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1413 # signal netdata to start saving its database
1414 # this is handy if your database is big
1415 pids=\$(pidof netdata)
1416 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1421 # we are running on a terminal
1422 # open fd 3 and send it to stderr
1426 # create a temporary file for the log
1427 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1428 # open fd 3 and send it to tmp
1433 echo >&3 "\$(date) : INFO: " "\${@}"
1441 echo >&3 "\$(date) : ERROR: " "\${@}"
1444 # this is what we will do if it fails (head-less only)
1446 error "FAILED TO UPDATE NETDATA : \${1}"
1448 if [ ! -z "\${tmp}" ]
1456 get_latest_commit_id() {
1458 grep ^commit 2>&3 |\\
1460 cut -d ' ' -f 2 2>&3
1464 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1470 info "Updating netdata source from github..."
1472 last_commit="\$(get_latest_commit_id)"
1473 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1475 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1477 new_commit="\$(get_latest_commit_id)"
1478 if [ \${force} -eq 0 ]
1480 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1481 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1483 elif [ \${force} -eq 0 ]
1485 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1489 info "Re-installing netdata..."
1490 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1492 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1496 # the installer updates this script - so we run and exit in a single line
1498 ###############################################################################
1499 ###############################################################################
1501 chmod 755 netdata-updater.sh.new
1502 mv -f netdata-updater.sh.new netdata-updater.sh
1503 echo >&2 "Update script generated : ./netdata-updater.sh"
1504 elif [ -f "netdata-updater.sh" ]
1506 rm "netdata-updater.sh"
1509 banner "is installed and running now!"
1510 echo >&2 " enjoy real-time performance and health monitoring..."