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 2>/dev/null | 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 setcap="$(which setcap 2>/dev/null || command -v setcap 2>/dev/null)"
73 service="$(which service 2>/dev/null || command -v service 2>/dev/null)"
74 systemctl="$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)"
76 local cmd="${1}" action="${2}"
78 if [ ! -z "${service}" ]
80 run "${service}" "${cmd}" "${action}"
82 elif [ ! -z "${systemctl}" ]
84 run "${systemctl}" "${action}" "${cmd}"
97 banner "installer command line options"
100 ${ME} <installer options>
102 Valid <installer options> are:
104 --install /PATH/TO/INSTALL
106 If your give: --install /opt
107 netdata will be installed in /opt/netdata
111 Do not (re)start netdata.
116 Do not wait for the user to press ENTER.
117 Start immediately building it.
119 --zlib-is-really-here
120 --libs-are-really-here
122 If you get errors about missing zlib,
123 or libuuid but you know it is available,
124 you have a broken pkg-config.
125 Use this option to allow it continue
126 without checking pkg-config.
128 Netdata will by default be compiled with gcc optimization -O2
129 If you need to pass different CFLAGS, use something like this:
131 CFLAGS="<gcc options>" ${ME} <installer options>
133 For the installer to complete successfully, you will need
134 these packages installed:
136 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
137 uuid-dev (or libuuid-devel)
139 For the plugins, you will at least need:
146 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null)"
147 get_git_config_signatures() {
150 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
151 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
153 echo >configs.signatures.tmp
155 for x in $(find conf.d -name \*.conf)
159 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
161 git checkout ${c} "conf.d/${x}" || continue
162 s="$(cat "conf.d/${x}" | md5sum | cut -d ' ' -f 1)"
163 echo >>configs.signatures.tmp "${s}:${x}"
166 git checkout HEAD "conf.d/${x}" || break
169 cat configs.signatures.tmp |\
173 echo "declare -A configs_signatures=("
177 echo " ['${md5}']='${file}'"
180 } >configs.signatures
182 rm configs.signatures.tmp
188 while [ ! -z "${1}" ]
190 if [ "$1" = "--install" ]
192 NETDATA_PREFIX="${2}/netdata"
194 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
198 elif [ "$1" = "--dont-start-it" ]
202 elif [ "$1" = "--dont-wait" ]
206 elif [ "$1" = "--help" -o "$1" = "-h" ]
210 elif [ "$1" = "get_git_config_signatures" ]
212 get_git_config_signatures && exit 0
217 echo >&2 "I cannot understand option '$1'."
223 banner "real-time performance monitoring, done right!"
226 You are about to build and install netdata to your system.
228 It will be installed at these locations:
230 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
231 - config files at ${NETDATA_PREFIX}/etc/netdata
232 - web files at ${NETDATA_PREFIX}/usr/share/netdata
233 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
234 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
235 - db files at ${NETDATA_PREFIX}/var/lib/netdata
236 - log files at ${NETDATA_PREFIX}/var/log/netdata
237 - pid file at ${NETDATA_PREFIX}/var/run
239 This installer allows you to change the installation path.
240 Press Control-C and run the same command with --help for help.
244 if [ "${UID}" -ne 0 ]
246 if [ -z "${NETDATA_PREFIX}" ]
248 banner "wrong command line options!"
249 cat <<NONROOTNOPREFIX
251 Sorry! This will fail!
253 You are attempting to install netdata as non-root, but you plan to install it
256 Please set an installation prefix, like this:
258 $0 ${@} --install /tmp
260 or, run the installer as root:
264 We suggest to install it as root, or certain data collectors will not be able
265 to work. Netdata drops root privileges when running. So, if you plan to keep
266 it, install it as root to get the full functionality.
275 You are about to install netdata as a non-root user.
276 Netdata will work, but a few data collection modules that
277 require root access will fail.
279 If you installing permanently on your system, run the
289 if [ "$(type autoreconf 2> /dev/null)" ]
297 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
298 eval $maj=\$1 $min=\$2
300 autoconf_maj_min AMAJ AMIN
305 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
309 echo "Found autotools $AMAJ.$AMIN"
312 echo "No autotools found"
315 if [ ! "$have_autotools" ]
319 echo "Will skip autoreconf step"
321 banner "autotools v2.60 required"
324 -------------------------------------------------------------------------------
325 autotools 2.60 or later is required
327 Sorry, you do not seem to have autotools 2.60 or later, which is
328 required to build from the git sources of netdata.
330 You can either install a suitable version of autotools and automake
331 or download a netdata package which does not have these dependencies.
333 Source packages where autotools have already been run are available
335 https://firehol.org/download/netdata/
337 The unsigned/master folder tracks the head of the git tree and released
338 packages are also available.
344 if [ ${DONOTWAIT} -eq 0 ]
346 if [ ! -z "${NETDATA_PREFIX}" ]
348 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
350 read -p "Press ENTER to build and install netdata to your system > "
355 banner "sorry, it failed to build..."
358 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
360 Sorry! netdata failed to build...
362 You many need to check these:
364 1. The package uuid-dev (or libuuid-devel) has to be installed.
366 If your system cannot find libuuid, although it is installed
367 run me with the option: --libs-are-really-here
369 2. The package zlib1g-dev (or zlib-devel) has to be installed.
371 If your system cannot find zlib, although it is installed
372 run me with the option: --libs-are-really-here
374 3. You need basic build tools installed, like:
376 gcc make autoconf automake pkg-config
378 Autoconf version 2.60 or higher is required.
380 If you still cannot get it to build, ask for help at github:
382 https://github.com/firehol/netdata/issues
391 printf >>netdata-installer.log "# "
392 printf >>netdata-installer.log "%q " "${@}"
393 printf >>netdata-installer.log " ... "
396 printf >&2 ":-----------------------------------------------------------------------------\n"
397 printf >&2 "Running command (in $(pwd)):\n"
399 printf >&2 "%q " "${@}"
407 printf >>netdata-installer.log "FAILED!\n"
409 printf >>netdata-installer.log "OK\n"
415 if [ ${LIBS_ARE_HERE} -eq 1 ]
418 echo >&2 "ok, assuming libs are really installed."
419 export ZLIB_CFLAGS=" "
420 export ZLIB_LIBS="-lz"
421 export UUID_CFLAGS=" "
422 export UUID_LIBS="-luuid"
425 trap build_error EXIT
427 if [ "$have_autotools" ]
429 run ./autogen.sh || exit 1
433 --prefix="${NETDATA_PREFIX}/usr" \
434 --sysconfdir="${NETDATA_PREFIX}/etc" \
435 --localstatedir="${NETDATA_PREFIX}/var" \
436 --with-zlib --with-math --with-user=netdata \
437 CFLAGS="${CFLAGS}" || exit 1
439 # remove the build_error hook
442 if [ -f src/netdata ]
444 echo >&2 "Cleaning a possibly old compilation ..."
448 echo >&2 "Compiling netdata ..."
449 run make -j${processors} || exit 1
451 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
453 declare -A configs_signatures=()
454 if [ -f "configs.signatures" ]
456 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
460 # migrate existing configuration files
461 # for node.d and charts.d
462 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
464 # the configuration directory exists
466 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
468 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
471 # move the charts.d config files
472 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
474 for y in "" ".old" ".orig"
476 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
478 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
483 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
485 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
488 # move the node.d config files
489 for x in named sma_webbox snmp
491 for y in "" ".old" ".orig"
493 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
495 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
501 # backup user configurations
502 installer_backup_suffix="${PID}.${RANDOM}"
503 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
507 # make a backup of the configuration file
508 cp -p "${x}" "${x}.old"
510 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
512 # we don't have md5sum - keep it
513 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
515 # find it relative filename
516 f="${x/*\/etc\/netdata\//}"
519 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
522 if [ -f "conf.d/${f}" ]
524 cp "conf.d/${f}" "${x}.orig"
527 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
529 if [ "${configs_signatures[${md5}]}" = "${f}" ]
531 # it is a stock version - don't keep it
532 echo >&2 "File '${x}' is stock version."
534 # edited by user - keep it
535 echo >&2 "File '${x}' has been edited by user."
536 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
539 echo >&2 "File '${x}' cannot be check for custom edits."
540 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
544 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
546 rm -f "${x}.installer_backup.${installer_backup_suffix}"
550 echo >&2 "Installing netdata ..."
551 run make install || exit 1
553 # restore user configurations
554 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
556 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
558 cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
559 rm -f "${x}.installer_backup.${installer_backup_suffix}"
563 echo >&2 "Fixing permissions ..."
566 which "${1}" >/dev/null 2>&1 && return 0
567 command -v "${1}" >/dev/null 2>&1 && return 0
571 portable_add_user() {
572 local username="${1}"
574 getent passwd "${username}" > /dev/null 2>&1
575 [ $? -eq 0 ] && return 0
577 echo >&2 "Adding ${username} user account ..."
579 local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
584 run useradd -r -g "${username}" -c "${username}" -s "${nologin}" -d / "${username}" && return 0
590 run pw useradd "${username}" -d / -g "${username}" -s "${nologin}" && return 0
596 run adduser -D -G "${username}" "${username}" && return 0
599 echo >&2 "Failed to add ${username} user account !"
604 portable_add_group() {
605 local groupname="${1}"
607 getent group "${groupname}" > /dev/null 2>&1
608 [ $? -eq 0 ] && return 0
610 echo >&2 "Adding ${groupname} user group ..."
613 if check_cmd groupadd
615 run groupadd -r "${groupname}" && return 0
621 run pw groupadd "${groupname}" && return 0
625 if check_cmd addgroup
627 run addgroup "${groupname}" && return 0
630 echo >&2 "Failed to add ${groupname} user group !"
634 portable_add_user_to_group() {
635 local groupname="${1}" username="${2}"
637 getent group "${groupname}" > /dev/null 2>&1
638 [ $? -ne 0 ] && return 1
640 # find the user is already in the group
641 local users=$(getent group "${groupname}" | cut -d ':' -f 4)
642 if [[ ",${users}," =~ ,${username}, ]]
644 # username is already there
647 # username is not in group
648 echo >&2 "Adding ${username} user to the ${groupname} group ..."
653 run usermod -a -G "${groupname}" "${username}" && return 0
659 run pw groupmod "${groupname}" -m "${username}" && return 0
663 if check_cmd addgroup
665 run addgroup "${username}" "${groupname}" && return 0
668 echo >&2 "Failed to add user ${username} to group ${groupname} !"
674 # man systemd-detect-virt
675 local cmd=$(which systemd-detect-virt 2>/dev/null || command -v systemd-detect-virt 2>/dev/null)
676 if [ ! -z "${cmd}" -a -x "${cmd}" ]
678 "${cmd}" --container >/dev/null 2>&1 && return 0
681 # /proc/1/sched exposes the host's pid of our init !
682 # http://stackoverflow.com/a/37016302
683 local pid=$( cat /proc/1/sched | head -n 1 | { IFS='(),#:' read name pid th threads; echo $pid; } )
684 local p=$(( pid + 0 ))
685 [ ${pid} -ne 1 ] && return 0
687 # lxc sets environment variable 'container'
688 [ ! -z "${container}" ] && return 0
690 # docker creates /.dockerenv
691 # http://stackoverflow.com/a/25518345
692 [ -f "/.dockerenv" ] && return 0
694 # ubuntu and debian supply /bin/running-in-container
695 # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
696 if [ -x "/bin/running-in-container" ]
698 "/bin/running-in-container" >/dev/null 2>&1 && return 0
704 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
706 NETDATA_ADDED_TO_DOCKER=0
707 NETDATA_ADDED_TO_NGINX=0
708 NETDATA_ADDED_TO_VARNISH=0
709 NETDATA_ADDED_TO_HAPROXY=0
710 NETDATA_ADDED_TO_ADM=0
713 portable_add_group netdata
714 portable_add_user netdata
715 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
716 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
717 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
718 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
719 portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
721 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
723 echo >&2 "Adding netdata logrotate configuration ..."
724 run cp system/netdata.logrotate /etc/logrotate.d/netdata
727 if [ -f /etc/logrotate.d/netdata ]
729 echo >&2 "Fixing netdata logrotate permissions ..."
730 run chmod 644 /etc/logrotate.d/netdata
735 # -----------------------------------------------------------------------------
736 # load options from the configuration file
738 # create an empty config if it does not exist
739 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
741 # function to extract values from the config file
743 local key="${1}" value="${2}" line=
745 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
747 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
748 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
754 # the user netdata will run as
755 if [ "${UID}" = "0" ]
757 NETDATA_USER="$( config_option "run as user" "netdata" )"
759 NETDATA_USER="${USER}"
762 # the owners of the web files
763 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
764 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
767 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
771 NETDATA_PORT="$( config_option "default port" ${defport} )"
772 NETDATA_PORT2="$( config_option "port" ${defport} )"
774 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
776 if [ "${NETDATA_PORT2}" != "${defport}" ]
778 NETDATA_PORT="${NETDATA_PORT2}"
783 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
784 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
785 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
786 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
787 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
788 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
791 # -----------------------------------------------------------------------------
792 # prepare the directories
794 # this is needed if NETDATA_PREFIX is not empty
795 if [ ! -d "${NETDATA_RUN_DIR}" ]
797 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
801 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
805 for x in "python.d" "charts.d" "node.d"
807 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
809 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
810 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
813 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
814 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
815 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
819 if [ ! -d "${NETDATA_WEB_DIR}" ]
821 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
822 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
824 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
825 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
826 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
830 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
834 echo >&2 "Creating directory '${x}'"
835 run mkdir -p "${x}" || exit 1
838 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
839 #run find "${x}" -type f -exec chmod 0660 {} \;
840 #run find "${x}" -type d -exec chmod 0770 {} \;
843 run chmod 755 "${NETDATA_LOG_DIR}"
849 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
850 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
851 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
852 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
853 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
854 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
859 if [ ! -z "${setcap}" ]
861 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
865 if [ ${setcap_ret} -eq 0 ]
867 # if we managed to setcap
868 # but we fail to execute apps.plugin
869 # trigger setuid to root
870 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
875 if [ ${setcap_ret} -ne 0 ]
877 # fix apps.plugin to be setuid to root
878 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
879 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
882 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
883 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
884 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
885 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
888 # --- fix #1292 bug ---
890 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
891 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
894 # -----------------------------------------------------------------------------
895 # check if we can re-start netdata
897 if [ ${DONOTSTART} -eq 1 ]
899 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
901 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
902 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
904 if [ "${UID}" -eq 0 ]
906 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
908 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
910 banner "is installed now!"
911 echo >&2 " enjoy real-time performance and health monitoring..."
915 # -----------------------------------------------------------------------------
916 # stop a running netdata
921 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
922 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
928 stop_netdata_on_pid() {
929 local pid="${1}" ret=0 count=0
931 isnetdata ${pid} || return 0
933 printf >&2 "Stopping netdata on pid ${pid} ..."
934 while [ ! -z "$pid" -a ${ret} -eq 0 ]
936 if [ ${count} -gt 45 ]
938 echo >&2 "Cannot stop the running netdata on pid ${pid}."
942 count=$(( count + 1 ))
944 run kill ${pid} 2>/dev/null
947 test ${ret} -eq 0 && printf >&2 "." && sleep 2
953 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
957 echo >&2 "netdata on pid ${pid} stopped."
964 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
966 echo >&2 "Stopping a (possibly) running netdata..."
968 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
969 $(cat /var/run/netdata.pid 2>/dev/null) \
970 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
971 $(pidof netdata 2>/dev/null)
973 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
975 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
977 stop_netdata_on_pid ${p}
982 # -----------------------------------------------------------------------------
986 local pids p myns ns systemctl
988 # if the directory /etc/systemd/system does not exit, it is not systemd
989 [ ! -d /etc/systemd/system ] && return 1
991 # if there is no systemctl command, it is not systemd
992 systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
993 [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
995 # if pid 1 is systemd, it is systemd
996 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
998 # if systemd is not running, it is not systemd
999 pids=$(pidof systemd 2>/dev/null)
1000 [ -z "${pids}" ] && return 1
1002 # check if the running systemd processes are not in our namespace
1003 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
1006 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
1008 # if pid of systemd is in our namespace, it is systemd
1009 [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
1012 # else, it is not systemd
1017 install_non_systemd_init() {
1018 [ "${UID}" != 0 ] && return 1
1021 if [ -f /etc/os-release ]
1023 source /etc/os-release || return 1
1024 key="${ID}-${VERSION_ID}"
1026 elif [ -f /etc/centos-release ]
1028 key=$(</etc/centos-release)
1031 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
1033 if [ "${key}" = "gentoo" ]
1035 run cp system/netdata-openrc /etc/init.d/netdata && \
1036 run chmod 755 /etc/init.d/netdata && \
1037 run rc-update add netdata default && \
1040 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
1042 run cp system/netdata-lsb /etc/init.d/netdata && \
1043 run chmod 755 /etc/init.d/netdata && \
1044 run update-rc.d netdata defaults && \
1045 run update-rc.d netdata enable && \
1048 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
1050 run cp system/netdata-init-d /etc/init.d/netdata && \
1051 run chmod 755 /etc/init.d/netdata && \
1052 run chkconfig netdata on && \
1061 if [ "${UID}" -eq 0 ]
1066 # systemd is running on this system
1068 if [ ! -f /etc/systemd/system/netdata.service ]
1070 echo >&2 "Installing systemd service..."
1071 run cp system/netdata.service /etc/systemd/system/netdata.service && \
1072 run systemctl daemon-reload && \
1073 run systemctl enable netdata
1075 service netdata stop
1079 service netdata restart && started=1
1081 install_non_systemd_init
1084 if [ ${started} -eq 0 ]
1086 # check if we can use the system service
1087 service netdata stop
1089 service netdata restart && started=1
1090 if [ ${started} -eq 0 ]
1092 service netdata start && started=1
1097 if [ ${started} -eq 0 ]
1099 # still not started...
1103 echo >&2 "Starting netdata..."
1104 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
1108 echo >&2 "SORRY! FAILED TO START NETDATA!"
1111 echo >&2 "OK. NetData Started!"
1117 # -----------------------------------------------------------------------------
1118 # save a config file, if it is not already there
1120 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
1123 echo >&2 "-------------------------------------------------------------------------------"
1125 echo >&2 "Downloading default configuration from netdata..."
1128 # remove a possibly obsolete download
1129 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1131 # disable a proxy to get data from the local netdata
1136 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1140 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1142 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1146 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1148 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1149 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1151 if [ "${UID}" -eq 0 ]
1153 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1155 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1157 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1158 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1162 # -----------------------------------------------------------------------------
1165 ksm_is_available_but_disabled() {
1168 -------------------------------------------------------------------------------
1169 Memory de-duplication instructions
1171 You have kernel memory de-duper (called Kernel Same-page Merging,
1172 or KSM) available, but it is not currently enabled.
1176 echo 1 >/sys/kernel/mm/ksm/run
1177 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
1179 If you enable it, you will save 40-60% of netdata memory.
1184 ksm_is_not_available() {
1187 -------------------------------------------------------------------------------
1188 Memory de-duplication not present in your kernel
1190 It seems you do not have kernel memory de-duper (called Kernel Same-page
1191 Merging, or KSM) available.
1193 To enable it, you need a kernel built with CONFIG_KSM=y
1195 If you can have it, you will save 40-60% of netdata memory.
1200 if [ -f "/sys/kernel/mm/ksm/run" ]
1202 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1204 ksm_is_available_but_disabled
1207 ksm_is_not_available
1210 # -----------------------------------------------------------------------------
1211 # Check for version.txt
1213 if [ ! -s web/version.txt ]
1217 -------------------------------------------------------------------------------
1218 Version update check warning
1220 The way you downloaded netdata, we cannot find its version. This means the
1221 Update check on the dashboard, will not work.
1223 If you want to have version update check, please re-install it
1224 following the procedure in:
1226 https://github.com/firehol/netdata/wiki/Installation
1231 # -----------------------------------------------------------------------------
1232 # apps.plugin warning
1234 if [ "${UID}" -ne 0 ]
1236 cat <<SETUID_WARNING
1238 -------------------------------------------------------------------------------
1239 apps.plugin needs privileges
1241 Since you have installed netdata as a normal user, to have apps.plugin collect
1242 all the needed data, you have to give it the access rights it needs, by running
1243 either of the following sets of commands:
1245 To run apps.plugin with escalated capabilities:
1247 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1248 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1249 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1251 or, to run apps.plugin as root:
1253 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1254 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1256 apps.plugin is performing a hard-coded function of data collection for all
1257 running processes. It cannot be instructed from the netdata daemon to perform
1258 any task, so it is pretty safe to do this.
1263 # -----------------------------------------------------------------------------
1264 # Keep un-install info
1266 cat >netdata-uninstaller.sh <<UNINSTALL
1269 # this script will uninstall netdata
1271 if [ "\$1" != "--force" ]
1273 echo >&2 "This script will REMOVE netdata from your system."
1274 echo >&2 "Run it again with --force to do it."
1278 echo >&2 "Stopping a possibly running netdata..."
1279 for p in \$(pidof netdata); do kill \$p; done
1283 if [ ! -z "\$1" -a -d "\$1" ]
1286 echo "Deleting directory '\$1' ..."
1291 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1293 # installation prefix was given
1295 deletedir "${NETDATA_PREFIX}"
1298 # installation prefix was NOT given
1300 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1302 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1303 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1306 deletedir "${NETDATA_PREFIX}/etc/netdata"
1307 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1308 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1309 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1310 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1311 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1314 if [ -f /etc/logrotate.d/netdata ]
1316 echo "Deleting /etc/logrotate.d/netdata ..."
1317 rm -i /etc/logrotate.d/netdata
1320 if [ -f /etc/systemd/system/netdata.service ]
1322 echo "Deleting /etc/systemd/system/netdata.service ..."
1323 rm -i /etc/systemd/system/netdata.service
1326 if [ -f /etc/init.d/netdata ]
1328 echo "Deleting /etc/init.d/netdata ..."
1329 rm -i /etc/init.d/netdata
1332 getent passwd netdata > /dev/null
1336 echo "You may also want to remove the user netdata"
1338 echo " userdel netdata"
1341 getent group netdata > /dev/null
1345 echo "You may also want to remove the group netdata"
1347 echo " groupdel netdata"
1350 getent group docker > /dev/null
1351 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1354 echo "You may also want to remove the netdata user from the docker group"
1356 echo " gpasswd -d netdata docker"
1359 getent group nginx > /dev/null
1360 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1363 echo "You may also want to remove the netdata user from the nginx group"
1365 echo " gpasswd -d netdata nginx"
1368 getent group varnish > /dev/null
1369 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1372 echo "You may also want to remove the netdata user from the varnish group"
1374 echo " gpasswd -d netdata varnish"
1377 getent group haproxy > /dev/null
1378 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1381 echo "You may also want to remove the netdata user from the haproxy group"
1383 echo " gpasswd -d netdata haproxy"
1386 getent group adm > /dev/null
1387 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_ADM}" = "1" ]
1390 echo "You may also want to remove the netdata user from the adm group"
1392 echo " gpasswd -d netdata adm"
1397 chmod 750 netdata-uninstaller.sh
1399 # -----------------------------------------------------------------------------
1404 -------------------------------------------------------------------------------
1406 OK. NetData is installed and it is running.
1408 -------------------------------------------------------------------------------
1410 By default netdata listens on all IPs on port ${NETDATA_PORT},
1411 so you can access it with:
1413 http://this.machine.ip:${NETDATA_PORT}/
1415 To stop netdata, just kill it, with:
1419 To start it, just run it:
1421 ${NETDATA_PREFIX}/usr/sbin/netdata
1425 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1429 cat >netdata-updater.sh.new <<REINSTALL
1433 [ "\${1}" = "-f" ] && force=1
1435 export PATH="\${PATH}:${PATH}"
1436 export CFLAGS="${CFLAGS}"
1438 INSTALL_UID="${UID}"
1439 if [ "\${INSTALL_UID}" != "\${UID}" ]
1441 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1445 # make sure we cd to the working directory
1446 cd "${REINSTALL_PWD}" || exit 1
1448 # make sure there is .git here
1449 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1451 # signal netdata to start saving its database
1452 # this is handy if your database is big
1453 pids=\$(pidof netdata)
1454 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1459 # we are running on a terminal
1460 # open fd 3 and send it to stderr
1464 # create a temporary file for the log
1465 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1466 # open fd 3 and send it to tmp
1471 echo >&3 "\$(date) : INFO: " "\${@}"
1479 echo >&3 "\$(date) : ERROR: " "\${@}"
1482 # this is what we will do if it fails (head-less only)
1484 error "FAILED TO UPDATE NETDATA : \${1}"
1486 if [ ! -z "\${tmp}" ]
1494 get_latest_commit_id() {
1496 grep ^commit 2>&3 |\\
1498 cut -d ' ' -f 2 2>&3
1502 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1508 info "Updating netdata source from github..."
1510 last_commit="\$(get_latest_commit_id)"
1511 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1513 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1515 new_commit="\$(get_latest_commit_id)"
1516 if [ \${force} -eq 0 ]
1518 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1519 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1521 elif [ \${force} -eq 0 ]
1523 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1527 info "Re-installing netdata..."
1528 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1530 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1534 # the installer updates this script - so we run and exit in a single line
1536 ###############################################################################
1537 ###############################################################################
1539 chmod 755 netdata-updater.sh.new
1540 mv -f netdata-updater.sh.new netdata-updater.sh
1541 echo >&2 "Update script generated : ./netdata-updater.sh"
1542 elif [ -f "netdata-updater.sh" ]
1544 rm "netdata-updater.sh"
1547 banner "is installed and running now!"
1548 echo >&2 " enjoy real-time performance and health monitoring..."