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
712 portable_add_group netdata
713 portable_add_user netdata
714 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
715 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
716 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
717 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
719 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
721 echo >&2 "Adding netdata logrotate configuration ..."
722 run cp system/netdata.logrotate /etc/logrotate.d/netdata
725 if [ -f /etc/logrotate.d/netdata ]
727 echo >&2 "Fixing netdata logrotate permissions ..."
728 run chmod 644 /etc/logrotate.d/netdata
733 # -----------------------------------------------------------------------------
734 # load options from the configuration file
736 # create an empty config if it does not exist
737 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
739 # function to extract values from the config file
741 local key="${1}" value="${2}" line=
743 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
745 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
746 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
752 # the user netdata will run as
753 if [ "${UID}" = "0" ]
755 NETDATA_USER="$( config_option "run as user" "netdata" )"
757 NETDATA_USER="${USER}"
760 # the owners of the web files
761 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
762 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
765 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
769 NETDATA_PORT="$( config_option "default port" ${defport} )"
770 NETDATA_PORT2="$( config_option "port" ${defport} )"
772 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
774 if [ "${NETDATA_PORT2}" != "${defport}" ]
776 NETDATA_PORT="${NETDATA_PORT2}"
781 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
782 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
783 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
784 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
785 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
786 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
789 # -----------------------------------------------------------------------------
790 # prepare the directories
792 # this is needed if NETDATA_PREFIX is not empty
793 if [ ! -d "${NETDATA_RUN_DIR}" ]
795 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
799 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
803 for x in "python.d" "charts.d" "node.d"
805 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
807 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
808 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
811 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
812 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
813 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
817 if [ ! -d "${NETDATA_WEB_DIR}" ]
819 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
820 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
822 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
823 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
824 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
828 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
832 echo >&2 "Creating directory '${x}'"
833 run mkdir -p "${x}" || exit 1
836 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
837 #run find "${x}" -type f -exec chmod 0660 {} \;
838 #run find "${x}" -type d -exec chmod 0770 {} \;
841 run chmod 755 "${NETDATA_LOG_DIR}"
847 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
848 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
849 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
850 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
851 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
852 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
857 if [ ! -z "${setcap}" ]
859 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
863 if [ ${setcap_ret} -eq 0 ]
865 # if we managed to setcap
866 # but we fail to execute apps.plugin
867 # trigger setuid to root
868 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
873 if [ ${setcap_ret} -ne 0 ]
875 # fix apps.plugin to be setuid to root
876 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
877 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
880 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
881 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
882 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
883 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
886 # --- fix #1292 bug ---
888 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
889 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
892 # -----------------------------------------------------------------------------
893 # check if we can re-start netdata
895 if [ ${DONOTSTART} -eq 1 ]
897 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
899 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
900 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
902 if [ "${UID}" -eq 0 ]
904 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
906 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
908 banner "is installed now!"
909 echo >&2 " enjoy real-time performance and health monitoring..."
913 # -----------------------------------------------------------------------------
914 # stop a running netdata
919 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
920 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
926 stop_netdata_on_pid() {
927 local pid="${1}" ret=0 count=0
929 isnetdata ${pid} || return 0
931 printf >&2 "Stopping netdata on pid ${pid} ..."
932 while [ ! -z "$pid" -a ${ret} -eq 0 ]
934 if [ ${count} -gt 45 ]
936 echo >&2 "Cannot stop the running netdata on pid ${pid}."
940 count=$(( count + 1 ))
942 run kill ${pid} 2>/dev/null
945 test ${ret} -eq 0 && printf >&2 "." && sleep 2
951 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
955 echo >&2 "netdata on pid ${pid} stopped."
962 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
964 echo >&2 "Stopping a (possibly) running netdata..."
966 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
967 $(cat /var/run/netdata.pid 2>/dev/null) \
968 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
969 $(pidof netdata 2>/dev/null)
971 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
973 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
975 stop_netdata_on_pid ${p}
980 # -----------------------------------------------------------------------------
984 local pids p myns ns systemctl
986 # if the directory /etc/systemd/system does not exit, it is not systemd
987 [ ! -d /etc/systemd/system ] && return 1
989 # if there is no systemctl command, it is not systemd
990 systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
991 [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
993 # if pid 1 is systemd, it is systemd
994 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
996 # if systemd is not running, it is not systemd
997 pids=$(pidof systemd 2>/dev/null)
998 [ -z "${pids}" ] && return 1
1000 # check if the running systemd processes are not in our namespace
1001 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
1004 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
1006 # if pid of systemd is in our namespace, it is systemd
1007 [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
1010 # else, it is not systemd
1015 install_non_systemd_init() {
1016 [ "${UID}" != 0 ] && return 1
1019 if [ -f /etc/os-release ]
1021 source /etc/os-release || return 1
1022 key="${ID}-${VERSION_ID}"
1024 elif [ -f /etc/centos-release ]
1026 key=$(</etc/centos-release)
1029 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
1031 if [ "${key}" = "gentoo" ]
1033 run cp system/netdata-openrc /etc/init.d/netdata && \
1034 run chmod 755 /etc/init.d/netdata && \
1035 run rc-update add netdata default && \
1038 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
1040 run cp system/netdata-lsb /etc/init.d/netdata && \
1041 run chmod 755 /etc/init.d/netdata && \
1042 run update-rc.d netdata defaults && \
1043 run update-rc.d netdata enable && \
1046 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
1048 run cp system/netdata-init-d /etc/init.d/netdata && \
1049 run chmod 755 /etc/init.d/netdata && \
1050 run chkconfig netdata on && \
1059 if [ "${UID}" -eq 0 ]
1064 # systemd is running on this system
1066 if [ ! -f /etc/systemd/system/netdata.service ]
1068 echo >&2 "Installing systemd service..."
1069 run cp system/netdata.service /etc/systemd/system/netdata.service && \
1070 run systemctl daemon-reload && \
1071 run systemctl enable netdata
1073 service netdata stop
1077 service netdata restart && started=1
1079 install_non_systemd_init
1082 if [ ${started} -eq 0 ]
1084 # check if we can use the system service
1085 service netdata stop
1087 service netdata restart && started=1
1088 if [ ${started} -eq 0 ]
1090 service netdata start && started=1
1095 if [ ${started} -eq 0 ]
1097 # still not started...
1101 echo >&2 "Starting netdata..."
1102 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
1106 echo >&2 "SORRY! FAILED TO START NETDATA!"
1109 echo >&2 "OK. NetData Started!"
1115 # -----------------------------------------------------------------------------
1116 # save a config file, if it is not already there
1118 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
1121 echo >&2 "-------------------------------------------------------------------------------"
1123 echo >&2 "Downloading default configuration from netdata..."
1126 # remove a possibly obsolete download
1127 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1129 # disable a proxy to get data from the local netdata
1134 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1138 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1140 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1144 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1146 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1147 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1149 if [ "${UID}" -eq 0 ]
1151 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1153 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1155 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1156 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1160 # -----------------------------------------------------------------------------
1163 ksm_is_available_but_disabled() {
1166 -------------------------------------------------------------------------------
1167 Memory de-duplication instructions
1169 You have kernel memory de-duper (called Kernel Same-page Merging,
1170 or KSM) available, but it is not currently enabled.
1174 echo 1 >/sys/kernel/mm/ksm/run
1175 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
1177 If you enable it, you will save 40-60% of netdata memory.
1182 ksm_is_not_available() {
1185 -------------------------------------------------------------------------------
1186 Memory de-duplication not present in your kernel
1188 It seems you do not have kernel memory de-duper (called Kernel Same-page
1189 Merging, or KSM) available.
1191 To enable it, you need a kernel built with CONFIG_KSM=y
1193 If you can have it, you will save 40-60% of netdata memory.
1198 if [ -f "/sys/kernel/mm/ksm/run" ]
1200 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1202 ksm_is_available_but_disabled
1205 ksm_is_not_available
1208 # -----------------------------------------------------------------------------
1209 # Check for version.txt
1211 if [ ! -s web/version.txt ]
1215 -------------------------------------------------------------------------------
1216 Version update check warning
1218 The way you downloaded netdata, we cannot find its version. This means the
1219 Update check on the dashboard, will not work.
1221 If you want to have version update check, please re-install it
1222 following the procedure in:
1224 https://github.com/firehol/netdata/wiki/Installation
1229 # -----------------------------------------------------------------------------
1230 # apps.plugin warning
1232 if [ "${UID}" -ne 0 ]
1234 cat <<SETUID_WARNING
1236 -------------------------------------------------------------------------------
1237 apps.plugin needs privileges
1239 Since you have installed netdata as a normal user, to have apps.plugin collect
1240 all the needed data, you have to give it the access rights it needs, by running
1241 either of the following sets of commands:
1243 To run apps.plugin with escalated capabilities:
1245 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1246 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1247 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1249 or, to run apps.plugin as root:
1251 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1252 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1254 apps.plugin is performing a hard-coded function of data collection for all
1255 running processes. It cannot be instructed from the netdata daemon to perform
1256 any task, so it is pretty safe to do this.
1261 # -----------------------------------------------------------------------------
1262 # Keep un-install info
1264 cat >netdata-uninstaller.sh <<UNINSTALL
1267 # this script will uninstall netdata
1269 if [ "\$1" != "--force" ]
1271 echo >&2 "This script will REMOVE netdata from your system."
1272 echo >&2 "Run it again with --force to do it."
1276 echo >&2 "Stopping a possibly running netdata..."
1277 for p in \$(pidof netdata); do kill \$p; done
1281 if [ ! -z "\$1" -a -d "\$1" ]
1284 echo "Deleting directory '\$1' ..."
1289 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1291 # installation prefix was given
1293 deletedir "${NETDATA_PREFIX}"
1296 # installation prefix was NOT given
1298 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1300 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1301 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1304 deletedir "${NETDATA_PREFIX}/etc/netdata"
1305 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1306 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1307 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1308 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1309 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1312 if [ -f /etc/logrotate.d/netdata ]
1314 echo "Deleting /etc/logrotate.d/netdata ..."
1315 rm -i /etc/logrotate.d/netdata
1318 if [ -f /etc/systemd/system/netdata.service ]
1320 echo "Deleting /etc/systemd/system/netdata.service ..."
1321 rm -i /etc/systemd/system/netdata.service
1324 if [ -f /etc/init.d/netdata ]
1326 echo "Deleting /etc/init.d/netdata ..."
1327 rm -i /etc/init.d/netdata
1330 getent passwd netdata > /dev/null
1334 echo "You may also want to remove the user netdata"
1336 echo " userdel netdata"
1339 getent group netdata > /dev/null
1343 echo "You may also want to remove the group netdata"
1345 echo " groupdel netdata"
1348 getent group docker > /dev/null
1349 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1352 echo "You may also want to remove the netdata user from the docker group"
1354 echo " gpasswd -d netdata docker"
1357 getent group nginx > /dev/null
1358 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1361 echo "You may also want to remove the netdata user from the nginx group"
1363 echo " gpasswd -d netdata nginx"
1366 getent group varnish > /dev/null
1367 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1370 echo "You may also want to remove the netdata user from the varnish group"
1372 echo " gpasswd -d netdata varnish"
1375 getent group haproxy > /dev/null
1376 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1379 echo "You may also want to remove the netdata user from the haproxy group"
1381 echo " gpasswd -d netdata haproxy"
1386 chmod 750 netdata-uninstaller.sh
1388 # -----------------------------------------------------------------------------
1393 -------------------------------------------------------------------------------
1395 OK. NetData is installed and it is running.
1397 -------------------------------------------------------------------------------
1399 By default netdata listens on all IPs on port ${NETDATA_PORT},
1400 so you can access it with:
1402 http://this.machine.ip:${NETDATA_PORT}/
1404 To stop netdata, just kill it, with:
1408 To start it, just run it:
1410 ${NETDATA_PREFIX}/usr/sbin/netdata
1414 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1418 cat >netdata-updater.sh.new <<REINSTALL
1422 [ "\${1}" = "-f" ] && force=1
1424 export PATH="\${PATH}:${PATH}"
1425 export CFLAGS="${CFLAGS}"
1427 INSTALL_UID="${UID}"
1428 if [ "\${INSTALL_UID}" != "\${UID}" ]
1430 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1434 # make sure we cd to the working directory
1435 cd "${REINSTALL_PWD}" || exit 1
1437 # make sure there is .git here
1438 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1440 # signal netdata to start saving its database
1441 # this is handy if your database is big
1442 pids=\$(pidof netdata)
1443 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1448 # we are running on a terminal
1449 # open fd 3 and send it to stderr
1453 # create a temporary file for the log
1454 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1455 # open fd 3 and send it to tmp
1460 echo >&3 "\$(date) : INFO: " "\${@}"
1468 echo >&3 "\$(date) : ERROR: " "\${@}"
1471 # this is what we will do if it fails (head-less only)
1473 error "FAILED TO UPDATE NETDATA : \${1}"
1475 if [ ! -z "\${tmp}" ]
1483 get_latest_commit_id() {
1485 grep ^commit 2>&3 |\\
1487 cut -d ' ' -f 2 2>&3
1491 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1497 info "Updating netdata source from github..."
1499 last_commit="\$(get_latest_commit_id)"
1500 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1502 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1504 new_commit="\$(get_latest_commit_id)"
1505 if [ \${force} -eq 0 ]
1507 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1508 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1510 elif [ \${force} -eq 0 ]
1512 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1516 info "Re-installing netdata..."
1517 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1519 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1523 # the installer updates this script - so we run and exit in a single line
1525 ###############################################################################
1526 ###############################################################################
1528 chmod 755 netdata-updater.sh.new
1529 mv -f netdata-updater.sh.new netdata-updater.sh
1530 echo >&2 "Update script generated : ./netdata-updater.sh"
1531 elif [ -f "netdata-updater.sh" ]
1533 rm "netdata-updater.sh"
1536 banner "is installed and running now!"
1537 echo >&2 " enjoy real-time performance and health monitoring..."