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--O3}"
27 # keep a log of this command
28 printf "\n# " >>netdata-installer.log
29 date >>netdata-installer.log
30 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
31 printf "%q " "$0" "${@}" >>netdata-installer.log
32 printf "\n" >>netdata-installer.log
34 REINSTALL_PWD="${PWD}"
35 REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
39 l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
40 l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
41 l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
43 netdata="netdata" start end msg="${*}"
45 [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
46 [ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
48 start="$(( ${#l2} / 2 - 4 ))"
49 [ $(( start + ${#msg} + 4 )) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
50 end=$(( ${start} + ${#msg} + 4 ))
54 echo >&2 "${l2:0:start}${sp:0:2}${netdata}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}"
55 echo >&2 "${l3:0:start}${sp:0:2}${msg}${sp:0:2}${l3:end:$((${#l2} - end))}"
60 service="$(which service 2>/dev/null || command -v service 2>/dev/null)"
61 systemctl="$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)"
63 local cmd="${1}" action="${2}"
65 if [ ! -z "${service}" ]
67 run "${service}" "${cmd}" "${action}"
69 elif [ ! -z "${systemctl}" ]
71 run "${systemctl}" "${action}" "${cmd}"
84 banner "installer command line options"
87 ${ME} <installer options>
89 Valid <installer options> are:
91 --install /PATH/TO/INSTALL
93 If your give: --install /opt
94 netdata will be installed in /opt/netdata
98 Do not (re)start netdata.
103 Do not wait for the user to press ENTER.
104 Start immediately building it.
106 --zlib-is-really-here
107 --libs-are-really-here
109 If you get errors about missing zlib,
110 or libuuid but you know it is available,
111 you have a broken pkg-config.
112 Use this option to allow it continue
113 without checking pkg-config.
115 Netdata will by default be compiled with gcc optimization -O3
116 If you need to pass different CFLAGS, use something like this:
118 CFLAGS="<gcc options>" ${ME} <installer options>
120 For the installer to complete successfully, you will need
121 these packages installed:
123 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
124 uuid-dev (or libuuid-devel)
126 For the plugins, you will at least need:
133 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null)"
134 get_git_config_signatures() {
137 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
138 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
140 echo >configs.signatures.tmp
142 for x in $(find conf.d -name \*.conf)
146 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
148 git checkout ${c} "conf.d/${x}" || continue
149 s="$(cat "conf.d/${x}" | md5sum | cut -d ' ' -f 1)"
150 echo >>configs.signatures.tmp "${s}:${x}"
153 git checkout HEAD "conf.d/${x}" || break
156 cat configs.signatures.tmp |\
160 echo "declare -A configs_signatures=("
164 echo " ['${md5}']='${file}'"
167 } >configs.signatures
169 rm configs.signatures.tmp
175 while [ ! -z "${1}" ]
177 if [ "$1" = "--install" ]
179 NETDATA_PREFIX="${2}/netdata"
181 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
185 elif [ "$1" = "--dont-start-it" ]
189 elif [ "$1" = "--dont-wait" ]
193 elif [ "$1" = "--help" -o "$1" = "-h" ]
197 elif [ "$1" = "get_git_config_signatures" ]
199 get_git_config_signatures && exit 0
204 echo >&2 "I cannot understand option '$1'."
210 banner "real-time performance monitoring, done right!"
213 You are about to build and install netdata to your system.
215 It will be installed at these locations:
217 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
218 - config files at ${NETDATA_PREFIX}/etc/netdata
219 - web files at ${NETDATA_PREFIX}/usr/share/netdata
220 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
221 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
222 - db files at ${NETDATA_PREFIX}/var/lib/netdata
223 - log files at ${NETDATA_PREFIX}/var/log/netdata
224 - pid file at ${NETDATA_PREFIX}/var/run
226 This installer allows you to change the installation path.
227 Press Control-C and run the same command with --help for help.
231 if [ "${UID}" -ne 0 ]
233 if [ -z "${NETDATA_PREFIX}" ]
235 banner "wrong command line options!"
236 cat <<NONROOTNOPREFIX
238 Sorry! This will fail!
240 You are attempting to install netdata as non-root, but you plan to install it
243 Please set an installation prefix, like this:
245 $0 ${@} --install /tmp
247 or, run the installer as root:
251 We suggest to install it as root, or certain data collectors will not be able
252 to work. Netdata drops root privileges when running. So, if you plan to keep
253 it, install it as root to get the full functionality.
262 You are about to install netdata as a non-root user.
263 Netdata will work, but a few data collection modules that
264 require root access will fail.
266 If you installing permanently on your system, run the
276 if [ "$(type autoreconf 2> /dev/null)" ]
284 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
285 eval $maj=\$1 $min=\$2
287 autoconf_maj_min AMAJ AMIN
292 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
296 echo "Found autotools $AMAJ.$AMIN"
299 echo "No autotools found"
302 if [ ! "$have_autotools" ]
306 echo "Will skip autoreconf step"
308 banner "autotools v2.60 required"
311 -------------------------------------------------------------------------------
312 autotools 2.60 or later is required
314 Sorry, you do not seem to have autotools 2.60 or later, which is
315 required to build from the git sources of netdata.
317 You can either install a suitable version of autotools and automake
318 or download a netdata package which does not have these dependencies.
320 Source packages where autotools have already been run are available
322 https://firehol.org/download/netdata/
324 The unsigned/master folder tracks the head of the git tree and released
325 packages are also available.
331 if [ ${DONOTWAIT} -eq 0 ]
333 if [ ! -z "${NETDATA_PREFIX}" ]
335 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
337 read -p "Press ENTER to build and install netdata to your system > "
342 banner "sorry, it failed to build..."
345 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
347 Sorry! netdata failed to build...
349 You many need to check these:
351 1. The package uuid-dev (or libuuid-devel) has to be installed.
353 If your system cannot find libuuid, although it is installed
354 run me with the option: --libs-are-really-here
356 2. The package zlib1g-dev (or zlib-devel) has to be installed.
358 If your system cannot find zlib, although it is installed
359 run me with the option: --libs-are-really-here
361 3. You need basic build tools installed, like:
363 gcc make autoconf automake pkg-config
365 Autoconf version 2.60 or higher is required.
367 If you still cannot get it to build, ask for help at github:
369 https://github.com/firehol/netdata/issues
378 printf >>netdata-installer.log "# "
379 printf >>netdata-installer.log "%q " "${@}"
380 printf >>netdata-installer.log " ... "
383 printf >&2 ":-----------------------------------------------------------------------------\n"
384 printf >&2 "Running command:\n"
386 printf >&2 "%q " "${@}"
394 printf >>netdata-installer.log "FAILED!\n"
396 printf >>netdata-installer.log "OK\n"
402 if [ ${LIBS_ARE_HERE} -eq 1 ]
405 echo >&2 "ok, assuming libs are really installed."
406 export ZLIB_CFLAGS=" "
407 export ZLIB_LIBS="-lz"
408 export UUID_CFLAGS=" "
409 export UUID_LIBS="-luuid"
412 trap build_error EXIT
414 if [ "$have_autotools" ]
416 run ./autogen.sh || exit 1
420 --prefix="${NETDATA_PREFIX}/usr" \
421 --sysconfdir="${NETDATA_PREFIX}/etc" \
422 --localstatedir="${NETDATA_PREFIX}/var" \
423 --with-zlib --with-math --with-user=netdata \
424 CFLAGS="${CFLAGS}" || exit 1
426 # remove the build_error hook
429 if [ -f src/netdata ]
431 echo >&2 "Cleaning a possibly old compilation ..."
435 echo >&2 "Compiling netdata ..."
436 run make -j${processors} || exit 1
438 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
440 declare -A configs_signatures=()
441 if [ -f "configs.signatures" ]
443 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
447 # migrate existing configuration files
448 # for node.d and charts.d
449 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
451 # the configuration directory exists
453 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
455 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
458 # move the charts.d config files
459 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
461 for y in "" ".old" ".orig"
463 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
465 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
470 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
472 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
475 # move the node.d config files
476 for x in named sma_webbox snmp
478 for y in "" ".old" ".orig"
480 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
482 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
488 # backup user configurations
489 installer_backup_suffix="${PID}.${RANDOM}"
490 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
494 # make a backup of the configuration file
495 cp -p "${x}" "${x}.old"
497 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
499 # we don't have md5sum - keep it
500 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
502 # find it relative filename
503 f="${x/*\/etc\/netdata\//}"
506 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
509 if [ -f "conf.d/${f}" ]
511 cp "conf.d/${f}" "${x}.orig"
514 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
516 if [ "${configs_signatures[${md5}]}" = "${f}" ]
518 # it is a stock version - don't keep it
519 echo >&2 "File '${x}' is stock version."
521 # edited by user - keep it
522 echo >&2 "File '${x}' has been edited by user."
523 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
526 echo >&2 "File '${x}' cannot be check for custom edits."
527 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
531 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
533 rm -f "${x}.installer_backup.${installer_backup_suffix}"
537 echo >&2 "Installing netdata ..."
538 run make install || exit 1
540 # restore user configurations
541 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
543 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
545 cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
546 rm -f "${x}.installer_backup.${installer_backup_suffix}"
550 echo >&2 "Fixing permissions ..."
553 which "${1}" >/dev/null 2>&1 && return 0
554 command -v "${1}" >/dev/null 2>&1 && return 0
558 portable_add_user() {
559 local username="${1}"
561 getent passwd "${username}" > /dev/null 2>&1
562 [ $? -eq 0 ] && return 0
564 echo >&2 "Adding ${username} user account ..."
566 local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
571 run useradd -r -g "${username}" -c "${username}" -s "${nologin}" -d / "${username}" && return 0
577 run pw useradd "${username}" -d / -g "${username}" -s "${nologin}" && return 0
583 run adduser -D -G "${username}" "${username}" && return 0
586 echo >&2 "Failed to add ${username} user account !"
591 portable_add_group() {
592 local groupname="${1}"
594 getent group "${groupname}" > /dev/null 2>&1
595 [ $? -eq 0 ] && return 0
597 echo >&2 "Adding ${groupname} user group ..."
600 if check_cmd groupadd
602 run groupadd -r "${groupname}" && return 0
608 run pw groupadd "${groupname}" && return 0
612 if check_cmd addgroup
614 run addgroup "${groupname}" && return 0
617 echo >&2 "Failed to add ${groupname} user group !"
621 portable_add_user_to_group() {
622 local groupname="${1}" username="${2}"
624 getent group "${groupname}" > /dev/null 2>&1
625 [ $? -ne 0 ] && return 1
627 # find the user is already in the group
628 local users=$(getent group "${groupname}" | cut -d ':' -f 4)
629 if [[ ",${users}," =~ ,${username}, ]]
631 # username is already there
634 # username is not in group
635 echo >&2 "Adding ${username} user to the ${groupname} group ..."
640 run usermod -a -G "${groupname}" "${username}" && return 0
646 run pw groupmod "${groupname}" -m "${username}" && return 0
650 if check_cmd addgroup
652 run addgroup "${username}" "${groupname}" && return 0
655 echo >&2 "Failed to add user ${username} to group ${groupname} !"
661 # man systemd-detect-virt
662 local cmd=$(which systemd-detect-virt 2>/dev/null || command -v systemd-detect-virt 2>/dev/null)
663 if [ ! -z "${cmd}" -a -x "${cmd}" ]
665 "${cmd}" --container >/dev/null 2>&1 && return 0
668 # /proc/1/sched exposes the host's pid of our init !
669 # http://stackoverflow.com/a/37016302
670 local pid=$( cat /proc/1/sched | head -n 1 | { IFS='(),#:' read name pid th threads; echo $pid; } )
671 local p=$(( pid + 0 ))
672 [ ${pid} -ne 1 ] && return 0
674 # lxc sets environment variable 'container'
675 [ ! -z "${container}" ] && return 0
677 # docker creates /.dockerenv
678 # http://stackoverflow.com/a/25518345
679 [ -f "/.dockerenv" ] && return 0
681 # ubuntu and debian supply /bin/running-in-container
682 # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
683 if [ -x "/bin/running-in-container" ]
685 "/bin/running-in-container" >/dev/null 2>&1 && return 0
691 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
693 NETDATA_ADDED_TO_DOCKER=0
694 NETDATA_ADDED_TO_NGINX=0
695 NETDATA_ADDED_TO_VARNISH=0
698 portable_add_group netdata
699 portable_add_user netdata
700 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
701 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
702 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
704 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
706 echo >&2 "Adding netdata logrotate configuration ..."
707 run cp system/netdata.logrotate /etc/logrotate.d/netdata
710 if [ -f /etc/logrotate.d/netdata ]
712 echo >&2 "Fixing netdata logrotate permissions ..."
713 run chmod 644 /etc/logrotate.d/netdata
718 # -----------------------------------------------------------------------------
719 # load options from the configuration file
721 # create an empty config if it does not exist
722 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
724 # function to extract values from the config file
726 local key="${1}" value="${2}" line=
728 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
730 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
731 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
737 # the user netdata will run as
738 if [ "${UID}" = "0" ]
740 NETDATA_USER="$( config_option "run as user" "netdata" )"
742 NETDATA_USER="${USER}"
745 # the owners of the web files
746 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
747 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
750 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
754 NETDATA_PORT="$( config_option "default port" ${defport} )"
755 NETDATA_PORT2="$( config_option "port" ${defport} )"
757 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
759 if [ "${NETDATA_PORT2}" != "${defport}" ]
761 NETDATA_PORT="${NETDATA_PORT2}"
766 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
767 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
768 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
769 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
770 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
771 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
774 # -----------------------------------------------------------------------------
775 # prepare the directories
777 # this is needed if NETDATA_PREFIX is not empty
778 if [ ! -d "${NETDATA_RUN_DIR}" ]
780 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
784 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
788 for x in "python.d" "charts.d" "node.d"
790 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
792 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
793 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
796 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
797 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
798 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
802 if [ ! -d "${NETDATA_WEB_DIR}" ]
804 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
805 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
807 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
808 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
809 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
813 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
817 echo >&2 "Creating directory '${x}'"
818 run mkdir -p "${x}" || exit 1
821 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
822 #run find "${x}" -type f -exec chmod 0660 {} \;
823 #run find "${x}" -type d -exec chmod 0770 {} \;
826 run chmod 755 "${NETDATA_LOG_DIR}"
832 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
833 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
834 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
835 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
836 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
837 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
842 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
845 if [ ${setcap_ret} -eq 0 ]
847 # if we managed to setcap
848 # but we fail to execute apps.plugin
849 # trigger setuid to root
850 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
855 if [ ${setcap_ret} -ne 0 ]
857 # fix apps.plugin to be setuid to root
858 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
859 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
862 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
863 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
864 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
865 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
868 # --- fix #1292 bug ---
870 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
871 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
874 # -----------------------------------------------------------------------------
875 # check if we can re-start netdata
877 if [ ${DONOTSTART} -eq 1 ]
879 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
881 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
882 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
884 if [ "${UID}" -eq 0 ]
886 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
888 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
890 banner "is installed now!"
891 echo >&2 " enjoy real-time performance and health monitoring..."
895 # -----------------------------------------------------------------------------
896 # stop a running netdata
901 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
902 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
908 stop_netdata_on_pid() {
909 local pid="${1}" ret=0 count=0
911 isnetdata ${pid} || return 0
913 printf >&2 "Stopping netdata on pid ${pid} ..."
914 while [ ! -z "$pid" -a ${ret} -eq 0 ]
916 if [ ${count} -gt 45 ]
918 echo >&2 "Cannot stop the running netdata on pid ${pid}."
922 count=$(( count + 1 ))
924 run kill ${pid} 2>/dev/null
927 test ${ret} -eq 0 && printf >&2 "." && sleep 2
933 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
937 echo >&2 "netdata on pid ${pid} stopped."
944 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
946 echo >&2 "Stopping a (possibly) running netdata..."
948 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
949 $(cat /var/run/netdata.pid 2>/dev/null) \
950 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
951 $(pidof netdata 2>/dev/null)
953 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
955 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
957 stop_netdata_on_pid ${p}
962 # -----------------------------------------------------------------------------
966 local pids p myns ns systemctl
968 # if the directory /etc/systemd/system does not exit, it is not systemd
969 [ ! -d /etc/systemd/system ] && return 1
971 # if there is no systemctl command, it is not systemd
972 systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
973 [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
975 # if pid 1 is systemd, it is systemd
976 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
978 # if systemd is not running, it is not systemd
979 pids=$(pidof systemd 2>/dev/null)
980 [ -z "${pids}" ] && return 1
982 # check if the running systemd processes are not in our namespace
983 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
986 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
988 # if pid of systemd is in our namespace, it is systemd
989 [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
992 # else, it is not systemd
997 install_non_systemd_init() {
998 [ "${UID}" != 0 ] && return 1
1001 if [ -f /etc/os-release ]
1003 source /etc/os-release || return 1
1004 key="${ID}-${VERSION_ID}"
1006 elif [ -f /etc/centos-release ]
1008 key=$(</etc/centos-release)
1011 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
1013 if [ "${key}" = "gentoo" ]
1015 run cp system/netdata-openrc /etc/init.d/netdata && \
1016 run chmod 755 /etc/init.d/netdata && \
1017 run rc-update add netdata default && \
1020 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
1022 run cp system/netdata-lsb /etc/init.d/netdata && \
1023 run chmod 755 /etc/init.d/netdata && \
1024 run update-rc.d netdata defaults && \
1025 run update-rc.d netdata enable && \
1028 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
1030 run cp system/netdata-init-d /etc/init.d/netdata && \
1031 run chmod 755 /etc/init.d/netdata && \
1032 run chkconfig netdata on && \
1041 if [ "${UID}" -eq 0 ]
1046 # systemd is running on this system
1048 if [ ! -f /etc/systemd/system/netdata.service ]
1050 echo >&2 "Installing systemd service..."
1051 run cp system/netdata.service /etc/systemd/system/netdata.service && \
1052 run systemctl daemon-reload && \
1053 run systemctl enable netdata
1055 service netdata stop
1059 service netdata restart && started=1
1061 install_non_systemd_init
1064 if [ ${started} -eq 0 ]
1066 # check if we can use the system service
1067 service netdata stop
1069 service netdata restart && started=1
1070 if [ ${started} -eq 0 ]
1072 service netdata start && started=1
1077 if [ ${started} -eq 0 ]
1079 # still not started...
1083 echo >&2 "Starting netdata..."
1084 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
1088 echo >&2 "SORRY! FAILED TO START NETDATA!"
1091 echo >&2 "OK. NetData Started!"
1097 # -----------------------------------------------------------------------------
1098 # save a config file, if it is not already there
1100 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
1103 echo >&2 "-------------------------------------------------------------------------------"
1105 echo >&2 "Downloading default configuration from netdata..."
1108 # remove a possibly obsolete download
1109 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1111 # disable a proxy to get data from the local netdata
1116 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1120 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1122 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1126 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1128 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1129 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1131 if [ "${UID}" -eq 0 ]
1133 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1135 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1137 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1138 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1142 # -----------------------------------------------------------------------------
1145 ksm_is_available_but_disabled() {
1148 -------------------------------------------------------------------------------
1149 Memory de-duplication instructions
1151 You have kernel memory de-duper (called Kernel Same-page Merging,
1152 or KSM) available, but it is not currently enabled.
1156 echo 1 >/sys/kernel/mm/ksm/run
1157 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
1159 If you enable it, you will save 40-60% of netdata memory.
1164 ksm_is_not_available() {
1167 -------------------------------------------------------------------------------
1168 Memory de-duplication not present in your kernel
1170 It seems you do not have kernel memory de-duper (called Kernel Same-page
1171 Merging, or KSM) available.
1173 To enable it, you need a kernel built with CONFIG_KSM=y
1175 If you can have it, you will save 40-60% of netdata memory.
1180 if [ -f "/sys/kernel/mm/ksm/run" ]
1182 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1184 ksm_is_available_but_disabled
1187 ksm_is_not_available
1190 # -----------------------------------------------------------------------------
1191 # Check for version.txt
1193 if [ ! -s web/version.txt ]
1197 -------------------------------------------------------------------------------
1198 Version update check warning
1200 The way you downloaded netdata, we cannot find its version. This means the
1201 Update check on the dashboard, will not work.
1203 If you want to have version update check, please re-install it
1204 following the procedure in:
1206 https://github.com/firehol/netdata/wiki/Installation
1211 # -----------------------------------------------------------------------------
1212 # apps.plugin warning
1214 if [ "${UID}" -ne 0 ]
1216 cat <<SETUID_WARNING
1218 -------------------------------------------------------------------------------
1219 apps.plugin needs privileges
1221 Since you have installed netdata as a normal user, to have apps.plugin collect
1222 all the needed data, you have to give it the access rights it needs, by running
1223 either of the following sets of commands:
1225 To run apps.plugin with escalated capabilities:
1227 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1228 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1229 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1231 or, to run apps.plugin as root:
1233 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1234 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
1236 apps.plugin is performing a hard-coded function of data collection for all
1237 running processes. It cannot be instructed from the netdata daemon to perform
1238 any task, so it is pretty safe to do this.
1243 # -----------------------------------------------------------------------------
1244 # Keep un-install info
1246 cat >netdata-uninstaller.sh <<UNINSTALL
1249 # this script will uninstall netdata
1251 if [ "\$1" != "--force" ]
1253 echo >&2 "This script will REMOVE netdata from your system."
1254 echo >&2 "Run it again with --force to do it."
1258 echo >&2 "Stopping a possibly running netdata..."
1259 for p in \$(pidof netdata); do kill \$p; done
1263 if [ ! -z "\$1" -a -d "\$1" ]
1266 echo "Deleting directory '\$1' ..."
1271 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1273 # installation prefix was given
1275 deletedir "${NETDATA_PREFIX}"
1278 # installation prefix was NOT given
1280 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1282 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1283 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1286 deletedir "${NETDATA_PREFIX}/etc/netdata"
1287 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1288 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1289 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1290 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1291 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1294 if [ -f /etc/logrotate.d/netdata ]
1296 echo "Deleting /etc/logrotate.d/netdata ..."
1297 rm -i /etc/logrotate.d/netdata
1300 if [ -f /etc/systemd/system/netdata.service ]
1302 echo "Deleting /etc/systemd/system/netdata.service ..."
1303 rm -i /etc/systemd/system/netdata.service
1306 if [ -f /etc/init.d/netdata ]
1308 echo "Deleting /etc/init.d/netdata ..."
1309 rm -i /etc/init.d/netdata
1312 getent passwd netdata > /dev/null
1316 echo "You may also want to remove the user netdata"
1318 echo " userdel netdata"
1321 getent group netdata > /dev/null
1325 echo "You may also want to remove the group netdata"
1327 echo " groupdel netdata"
1330 getent group docker > /dev/null
1331 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1334 echo "You may also want to remove the netdata user from the docker group"
1336 echo " gpasswd -d netdata docker"
1339 getent group nginx > /dev/null
1340 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1343 echo "You may also want to remove the netdata user from the nginx group"
1345 echo " gpasswd -d netdata nginx"
1348 getent group varnish > /dev/null
1349 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1352 echo "You may also want to remove the netdata user from the varnish group"
1354 echo " gpasswd -d netdata varnish"
1358 chmod 750 netdata-uninstaller.sh
1360 # -----------------------------------------------------------------------------
1365 -------------------------------------------------------------------------------
1367 OK. NetData is installed and it is running.
1369 -------------------------------------------------------------------------------
1371 By default netdata listens on all IPs on port ${NETDATA_PORT},
1372 so you can access it with:
1374 http://this.machine.ip:${NETDATA_PORT}/
1376 To stop netdata, just kill it, with:
1380 To start it, just run it:
1382 ${NETDATA_PREFIX}/usr/sbin/netdata
1386 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1390 cat >netdata-updater.sh.new <<REINSTALL
1394 [ "\${1}" = "-f" ] && force=1
1396 export PATH="\${PATH}:${PATH}"
1397 export CFLAGS="${CFLAGS}"
1399 INSTALL_UID="${UID}"
1400 if [ "\${INSTALL_UID}" != "\${UID}" ]
1402 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1406 # make sure we cd to the working directory
1407 cd "${REINSTALL_PWD}" || exit 1
1409 # make sure there is .git here
1410 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1412 # signal netdata to start saving its database
1413 # this is handy if your database is big
1414 pids=\$(pidof netdata)
1415 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1420 # we are running on a terminal
1421 # open fd 3 and send it to stderr
1425 # create a temporary file for the log
1426 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1427 # open fd 3 and send it to tmp
1432 echo >&3 "\$(date) : INFO: " "\${@}"
1440 echo >&3 "\$(date) : ERROR: " "\${@}"
1443 # this is what we will do if it fails (head-less only)
1445 error "FAILED TO UPDATE NETDATA : \${1}"
1447 if [ ! -z "\${tmp}" ]
1455 get_latest_commit_id() {
1457 grep ^commit 2>&3 |\\
1459 cut -d ' ' -f 2 2>&3
1463 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1469 info "Updating netdata source from github..."
1471 last_commit="\$(get_latest_commit_id)"
1472 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1474 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1476 new_commit="\$(get_latest_commit_id)"
1477 if [ \${force} -eq 0 ]
1479 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1480 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1482 elif [ \${force} -eq 0 ]
1484 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1488 info "Re-installing netdata..."
1489 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1491 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1495 # the installer updates this script - so we run and exit in a single line
1497 ###############################################################################
1498 ###############################################################################
1500 chmod 755 netdata-updater.sh.new
1501 mv -f netdata-updater.sh.new netdata-updater.sh
1502 echo >&2 "Update script generated : ./netdata-updater.sh"
1503 elif [ -f "netdata-updater.sh" ]
1505 rm "netdata-updater.sh"
1508 banner "is installed and running now!"
1509 echo >&2 " enjoy real-time performance and health monitoring..."