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}'."
14 # -----------------------------------------------------------------------------
15 # reload the user profile
17 [ -f /etc/profile ] && . /etc/profile
19 # make sure /etc/profile does not change our current directory
20 cd "${netdata_source_dir}" || exit 1
23 # -----------------------------------------------------------------------------
24 # load the required functions
26 if [ -f "${installer_dir}/installer/functions.sh" ]
28 source "${installer_dir}/installer/functions.sh" || exit 1
30 source "${netdata_source_dir}/installer/functions.sh" || exit 1
33 # make sure we save all commands we run
34 run_logfile="netdata-installer.log"
37 # -----------------------------------------------------------------------------
38 # fix PKG_CHECK_MODULES error
40 if [ -d /usr/share/aclocal ]
42 ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
49 # Be nice on production environments
50 renice 19 $$ >/dev/null 2>/dev/null
52 processors=$(grep ^processor </proc/cpuinfo 2>/dev/null | wc -l)
53 [ $(( processors )) -lt 1 ] && processors=1
55 # you can set CFLAGS before running installer
56 CFLAGS="${CFLAGS--O2}"
57 [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
59 # keep a log of this command
60 printf "\n# " >>netdata-installer.log
61 date >>netdata-installer.log
62 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
63 printf "%q " "$0" "${@}" >>netdata-installer.log
64 printf "\n" >>netdata-installer.log
66 REINSTALL_PWD="${PWD}"
67 REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
69 setcap="$(which setcap 2>/dev/null || command -v setcap 2>/dev/null)"
78 netdata_banner "installer command line options"
81 ${ME} <installer options>
83 Valid <installer options> are:
85 --install /PATH/TO/INSTALL
87 If your give: --install /opt
88 netdata will be installed in /opt/netdata
92 Do not (re)start netdata.
97 Do not wait for the user to press ENTER.
98 Start immediately building it.
100 --zlib-is-really-here
101 --libs-are-really-here
103 If you get errors about missing zlib,
104 or libuuid but you know it is available,
105 you have a broken pkg-config.
106 Use this option to allow it continue
107 without checking pkg-config.
109 Netdata will by default be compiled with gcc optimization -O2
110 If you need to pass different CFLAGS, use something like this:
112 CFLAGS="<gcc options>" ${ME} <installer options>
114 For the installer to complete successfully, you will need
115 these packages installed:
117 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
118 uuid-dev (or libuuid-devel)
120 For the plugins, you will at least need:
127 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null)"
128 get_git_config_signatures() {
131 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
132 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
134 echo >configs.signatures.tmp
136 for x in $(find conf.d -name \*.conf)
140 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
142 git checkout ${c} "conf.d/${x}" || continue
143 s="$(cat "conf.d/${x}" | md5sum | cut -d ' ' -f 1)"
144 echo >>configs.signatures.tmp "${s}:${x}"
147 git checkout HEAD "conf.d/${x}" || break
150 cat configs.signatures.tmp |\
154 echo "declare -A configs_signatures=("
158 echo " ['${md5}']='${file}'"
161 } >configs.signatures
163 rm configs.signatures.tmp
169 while [ ! -z "${1}" ]
171 if [ "$1" = "--install" ]
173 NETDATA_PREFIX="${2}/netdata"
175 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
179 elif [ "$1" = "--dont-start-it" ]
183 elif [ "$1" = "--dont-wait" ]
187 elif [ "$1" = "--help" -o "$1" = "-h" ]
191 elif [ "$1" = "get_git_config_signatures" ]
193 get_git_config_signatures && exit 0
198 echo >&2 "I cannot understand option '$1'."
204 netdata_banner "real-time performance monitoring, done right!"
207 You are about to build and install netdata to your system.
209 It will be installed at these locations:
211 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
212 - config files at ${NETDATA_PREFIX}/etc/netdata
213 - web files at ${NETDATA_PREFIX}/usr/share/netdata
214 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
215 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
216 - db files at ${NETDATA_PREFIX}/var/lib/netdata
217 - log files at ${NETDATA_PREFIX}/var/log/netdata
218 - pid file at ${NETDATA_PREFIX}/var/run
220 This installer allows you to change the installation path.
221 Press Control-C and run the same command with --help for help.
225 if [ "${UID}" -ne 0 ]
227 if [ -z "${NETDATA_PREFIX}" ]
229 netdata_banner "wrong command line options!"
230 cat <<NONROOTNOPREFIX
232 Sorry! This will fail!
234 You are attempting to install netdata as non-root, but you plan
235 to install it in system paths.
237 Please set an installation prefix, like this:
239 $0 ${@} --install /tmp
241 or, run the installer as root:
245 We suggest to install it as root, or certain data collectors will
246 not be able to work. Netdata drops root privileges when running.
247 So, if you plan to keep it, install it as root to get the full
257 You are about to install netdata as a non-root user.
258 Netdata will work, but a few data collection modules that
259 require root access will fail.
261 If you installing netdata permanently on your system, run
262 the installer like this:
271 if [ "$(type autoreconf 2> /dev/null)" ]
279 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
280 eval $maj=\$1 $min=\$2
282 autoconf_maj_min AMAJ AMIN
287 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
291 echo "Found autotools $AMAJ.$AMIN"
294 echo "No autotools found"
297 if [ ! "$have_autotools" ]
301 echo "Will skip autoreconf step"
303 netdata_banner "autotools v2.60 required"
306 -------------------------------------------------------------------------------
307 autotools 2.60 or later is required
309 Sorry, you do not seem to have autotools 2.60 or later, which is
310 required to build from the git sources of netdata.
312 You can either install a suitable version of autotools and automake
313 or download a netdata package which does not have these dependencies.
315 Source packages where autotools have already been run are available
317 https://firehol.org/download/netdata/
319 The unsigned/master folder tracks the head of the git tree and released
320 packages are also available.
326 if [ ${DONOTWAIT} -eq 0 ]
328 if [ ! -z "${NETDATA_PREFIX}" ]
330 eval "read >&2 -ep \$'\001${COLOR_BOLD}${COLOR_GREEN}\002Press ENTER to build and install netdata to \'\001${COLOR_CYAN}\002${NETDATA_PREFIX}\001${COLOR_YELLOW}\002\'\001${COLOR_RESET}\002 > ' -e -r REPLY"
332 eval "read >&2 -ep \$'\001${COLOR_BOLD}${COLOR_GREEN}\002Press ENTER to build and install netdata to your system\001${COLOR_RESET}\002 > ' -e -r REPLY"
337 netdata_banner "sorry, it failed to build..."
340 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
342 Sorry! netdata failed to build...
344 You many need to check these:
346 1. The package uuid-dev (or libuuid-devel) has to be installed.
348 If your system cannot find libuuid, although it is installed
349 run me with the option: --libs-are-really-here
351 2. The package zlib1g-dev (or zlib-devel) has to be installed.
353 If your system cannot find zlib, although it is installed
354 run me with the option: --libs-are-really-here
356 3. You need basic build tools installed, like:
358 gcc make autoconf automake pkg-config
360 Autoconf version 2.60 or higher is required.
362 If you still cannot get it to build, ask for help at github:
364 https://github.com/firehol/netdata/issues
372 if [ ${LIBS_ARE_HERE} -eq 1 ]
375 echo >&2 "ok, assuming libs are really installed."
376 export ZLIB_CFLAGS=" "
377 export ZLIB_LIBS="-lz"
378 export UUID_CFLAGS=" "
379 export UUID_LIBS="-luuid"
382 trap build_error EXIT
385 # -----------------------------------------------------------------------------
387 progress "Run autotools to configure the build environment"
389 if [ "$have_autotools" ]
391 run ./autogen.sh || exit 1
395 --prefix="${NETDATA_PREFIX}/usr" \
396 --sysconfdir="${NETDATA_PREFIX}/etc" \
397 --localstatedir="${NETDATA_PREFIX}/var" \
398 --with-zlib --with-math --with-user=netdata \
399 CFLAGS="${CFLAGS}" || exit 1
401 # remove the build_error hook
404 # -----------------------------------------------------------------------------
405 progress "Cleanup compilation directory"
407 [ -f src/netdata ] && run make clean
409 # -----------------------------------------------------------------------------
410 progress "Compile netdata"
412 run make -j${processors} || exit 1
415 # -----------------------------------------------------------------------------
416 progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
418 # migrate existing configuration files
419 # for node.d and charts.d
420 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
422 # the configuration directory exists
424 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
426 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
429 # move the charts.d config files
430 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
432 for y in "" ".old" ".orig"
434 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
436 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
441 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
443 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
446 # move the node.d config files
447 for x in named sma_webbox snmp
449 for y in "" ".old" ".orig"
451 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
453 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
459 # -----------------------------------------------------------------------------
460 progress "Backup existing netdata configuration before installing it"
462 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
464 declare -A configs_signatures=()
465 if [ -f "configs.signatures" ]
467 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
471 # backup user configurations
472 installer_backup_suffix="${PID}.${RANDOM}"
473 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
477 # make a backup of the configuration file
478 cp -p "${x}" "${x}.old"
480 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
482 # we don't have md5sum - keep it
483 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
485 # find it relative filename
486 f="${x/*\/etc\/netdata\//}"
489 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
492 if [ -f "conf.d/${f}" ]
494 cp "conf.d/${f}" "${x}.orig"
497 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
499 if [ "${configs_signatures[${md5}]}" = "${f}" ]
501 # it is a stock version - don't keep it
502 echo >&2 "File '${x}' is stock version."
504 # edited by user - keep it
505 echo >&2 "File '${x}' has been edited by user."
506 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
509 echo >&2 "File '${x}' cannot be check for custom edits."
510 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
514 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
516 rm -f "${x}.installer_backup.${installer_backup_suffix}"
521 # -----------------------------------------------------------------------------
522 progress "Install netdata"
524 run make install || exit 1
527 # -----------------------------------------------------------------------------
528 progress "Restore netdata configuration files"
530 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
532 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
534 cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
535 rm -f "${x}.installer_backup.${installer_backup_suffix}"
540 # -----------------------------------------------------------------------------
541 progress "Fix generated files permissions"
543 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
546 # -----------------------------------------------------------------------------
547 progress "Add user netdata to required user groups"
549 NETDATA_ADDED_TO_DOCKER=0
550 NETDATA_ADDED_TO_NGINX=0
551 NETDATA_ADDED_TO_VARNISH=0
552 NETDATA_ADDED_TO_HAPROXY=0
553 NETDATA_ADDED_TO_ADM=0
556 portable_add_group netdata
557 portable_add_user netdata
558 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
559 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
560 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
561 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
562 portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
566 # -----------------------------------------------------------------------------
567 progress "Install logrotate configuration for netdata"
571 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
573 run cp system/netdata.logrotate /etc/logrotate.d/netdata
576 if [ -f /etc/logrotate.d/netdata ]
578 run chmod 644 /etc/logrotate.d/netdata
583 # -----------------------------------------------------------------------------
584 progress "Read installation options from netdata.conf"
586 # create an empty config if it does not exist
587 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && \
588 touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
590 # function to extract values from the config file
592 local key="${1}" value="${2}" line=
594 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
596 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
597 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
603 # the user netdata will run as
604 if [ "${UID}" = "0" ]
606 NETDATA_USER="$( config_option "run as user" "netdata" )"
608 NETDATA_USER="${USER}"
611 # the owners of the web files
612 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
613 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
616 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
620 NETDATA_PORT="$( config_option "default port" ${defport} )"
621 NETDATA_PORT2="$( config_option "port" ${defport} )"
623 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
625 if [ "${NETDATA_PORT2}" != "${defport}" ]
627 NETDATA_PORT="${NETDATA_PORT2}"
632 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
633 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
634 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
635 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
636 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
637 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
640 # -----------------------------------------------------------------------------
641 progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
643 if [ ! -d "${NETDATA_RUN_DIR}" ]
645 # this is needed if NETDATA_PREFIX is not empty
646 run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
651 for x in "python.d" "charts.d" "node.d"
653 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
655 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
656 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
659 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
660 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
661 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
665 if [ ! -d "${NETDATA_WEB_DIR}" ]
667 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
668 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
670 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
671 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
672 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
676 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
680 echo >&2 "Creating directory '${x}'"
681 run mkdir -p "${x}" || exit 1
684 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
685 #run find "${x}" -type f -exec chmod 0660 {} \;
686 #run find "${x}" -type d -exec chmod 0770 {} \;
689 run chmod 755 "${NETDATA_LOG_DIR}"
695 run chown "${NETDATA_USER}:root" "${NETDATA_LOG_DIR}"
696 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
697 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
698 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
699 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
700 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
705 if [ ! -z "${setcap}" ]
707 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
711 if [ ${setcap_ret} -eq 0 ]
713 # if we managed to setcap
714 # but we fail to execute apps.plugin
715 # trigger setuid to root
716 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -v >/dev/null 2>&1
721 if [ ${setcap_ret} -ne 0 ]
723 # fix apps.plugin to be setuid to root
724 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
725 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
728 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
729 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
730 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
731 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
734 # --- fix #1292 bug ---
736 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
737 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
741 # -----------------------------------------------------------------------------
742 progress "Install netdata at system init"
745 install_non_systemd_init() {
746 [ "${UID}" != 0 ] && return 1
749 if [ -f /etc/os-release ]
751 source /etc/os-release || return 1
752 key="${ID}-${VERSION_ID}"
754 elif [ -f /etc/centos-release ]
756 key=$(</etc/centos-release)
759 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
761 if [ "${key}" = "gentoo" ]
763 run cp system/netdata-openrc /etc/init.d/netdata && \
764 run chmod 755 /etc/init.d/netdata && \
765 run rc-update add netdata default && \
768 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
770 run cp system/netdata-lsb /etc/init.d/netdata && \
771 run chmod 755 /etc/init.d/netdata && \
772 run update-rc.d netdata defaults && \
773 run update-rc.d netdata enable && \
776 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
778 run cp system/netdata-init-d /etc/init.d/netdata && \
779 run chmod 755 /etc/init.d/netdata && \
780 run chkconfig netdata on && \
788 if [ "${UID}" -eq 0 ]
793 # systemd is running on this system
795 if [ ! -f /etc/systemd/system/netdata.service ]
797 echo >&2 "Installing systemd service..."
798 run cp system/netdata.service /etc/systemd/system/netdata.service && \
799 run systemctl daemon-reload && \
800 run systemctl enable netdata
803 install_non_systemd_init
808 # -----------------------------------------------------------------------------
809 # check if we can re-start netdata
816 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
817 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
823 stop_netdata_on_pid() {
824 local pid="${1}" ret=0 count=0
826 isnetdata ${pid} || return 0
828 printf >&2 "Stopping netdata on pid ${pid} ..."
829 while [ ! -z "$pid" -a ${ret} -eq 0 ]
831 if [ ${count} -gt 45 ]
833 echo >&2 "Cannot stop the running netdata on pid ${pid}."
837 count=$(( count + 1 ))
839 run kill ${pid} 2>/dev/null
842 test ${ret} -eq 0 && printf >&2 "." && sleep 2
848 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
852 echo >&2 "netdata on pid ${pid} stopped."
859 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
861 echo >&2 "Stopping a (possibly) running netdata..."
863 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
864 $(cat /var/run/netdata.pid 2>/dev/null) \
865 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
866 $(pidof netdata 2>/dev/null)
868 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
870 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
872 stop_netdata_on_pid ${p}
877 if [ ${DONOTSTART} -eq 1 ]
879 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
881 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
883 if [ "${UID}" -eq 0 ]
885 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
887 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
892 progress "Start netdata"
894 if [ "${UID}" -eq 0 ]
898 service netdata restart && started=1
899 if [ ${started} -eq 0 ]
901 service netdata start && started=1
905 if [ ${started} -eq 0 ]
907 # still not started...
911 echo >&2 "Starting netdata..."
912 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
916 echo >&2 "SORRY! FAILED TO START NETDATA!"
919 echo >&2 "OK. NetData Started!"
925 # -----------------------------------------------------------------------------
926 # save a config file, if it is not already there
928 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
931 echo >&2 "-------------------------------------------------------------------------------"
933 echo >&2 "Downloading default configuration from netdata..."
936 # remove a possibly obsolete download
937 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
939 # disable a proxy to get data from the local netdata
944 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
948 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
950 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
954 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
956 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
957 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
959 if [ "${UID}" -eq 0 ]
961 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
963 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
965 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
966 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
971 # -----------------------------------------------------------------------------
972 progress "Check KSM (kernel memory deduper)"
974 ksm_is_available_but_disabled() {
977 Memory de-duplication instructions
979 You have kernel memory de-duper (called Kernel Same-page Merging,
980 or KSM) available, but it is not currently enabled.
984 $(printf "${COLOR_YELLOW}${COLOR_BOLD}echo 1 >/sys/kernel/mm/ksm/run${COLOR_RESET}")
985 $(printf "${COLOR_YELLOW}${COLOR_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${COLOR_RESET}")
987 If you enable it, you will save 40-60% of netdata memory.
992 ksm_is_not_available() {
995 Memory de-duplication not present in your kernel
997 It seems you do not have kernel memory de-duper (called Kernel Same-page
998 Merging, or KSM) available.
1000 To enable it, you need a kernel built with CONFIG_KSM=y
1002 If you can have it, you will save 40-60% of netdata memory.
1007 if [ -f "/sys/kernel/mm/ksm/run" ]
1009 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1011 ksm_is_available_but_disabled
1014 ksm_is_not_available
1017 # -----------------------------------------------------------------------------
1018 progress "Check version.txt"
1020 if [ ! -s web/version.txt ]
1024 Version update check warning
1026 The way you downloaded netdata, we cannot find its version. This means the
1027 Update check on the dashboard, will not work.
1029 If you want to have version update check, please re-install it
1030 following the procedure in:
1032 https://github.com/firehol/netdata/wiki/Installation
1037 # -----------------------------------------------------------------------------
1038 progress "Check apps.plugin"
1040 if [ "${UID}" -ne 0 ]
1042 cat <<SETUID_WARNING
1044 apps.plugin needs privileges
1046 Since you have installed netdata as a normal user, to have apps.plugin collect
1047 all the needed data, you have to give it the access rights it needs, by running
1048 either of the following sets of commands:
1050 To run apps.plugin with escalated capabilities:
1052 $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chown root:${NETDATA_USER} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
1053 $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
1054 $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo setcap cap_dac_read_search,cap_sys_ptrace+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
1056 or, to run apps.plugin as root:
1058 $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chown root \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
1059 $(printf "${COLOR_YELLOW}${COLOR_BOLD}sudo chmod 4755 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${COLOR_RESET}")
1061 apps.plugin is performing a hard-coded function of data collection for all
1062 running processes. It cannot be instructed from the netdata daemon to perform
1063 any task, so it is pretty safe to do this.
1068 # -----------------------------------------------------------------------------
1069 progress "Generate netdata-uninstaller.sh"
1071 cat >netdata-uninstaller.sh <<UNINSTALL
1074 # this script will uninstall netdata
1076 if [ "\$1" != "--force" ]
1078 echo >&2 "This script will REMOVE netdata from your system."
1079 echo >&2 "Run it again with --force to do it."
1083 echo >&2 "Stopping a possibly running netdata..."
1084 for p in \$(pidof netdata); do kill \$p; done
1088 if [ ! -z "\$1" -a -d "\$1" ]
1091 echo "Deleting directory '\$1' ..."
1096 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1098 # installation prefix was given
1100 deletedir "${NETDATA_PREFIX}"
1103 # installation prefix was NOT given
1105 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1107 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1108 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1111 deletedir "${NETDATA_PREFIX}/etc/netdata"
1112 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1113 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1114 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1115 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1116 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1119 if [ -f /etc/logrotate.d/netdata ]
1121 echo "Deleting /etc/logrotate.d/netdata ..."
1122 rm -i /etc/logrotate.d/netdata
1125 if [ -f /etc/systemd/system/netdata.service ]
1127 echo "Deleting /etc/systemd/system/netdata.service ..."
1128 rm -i /etc/systemd/system/netdata.service
1131 if [ -f /etc/init.d/netdata ]
1133 echo "Deleting /etc/init.d/netdata ..."
1134 rm -i /etc/init.d/netdata
1137 getent passwd netdata > /dev/null
1141 echo "You may also want to remove the user netdata"
1143 echo " userdel netdata"
1146 getent group netdata > /dev/null
1150 echo "You may also want to remove the group netdata"
1152 echo " groupdel netdata"
1155 getent group docker > /dev/null
1156 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1159 echo "You may also want to remove the netdata user from the docker group"
1161 echo " gpasswd -d netdata docker"
1164 getent group nginx > /dev/null
1165 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1168 echo "You may also want to remove the netdata user from the nginx group"
1170 echo " gpasswd -d netdata nginx"
1173 getent group varnish > /dev/null
1174 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1177 echo "You may also want to remove the netdata user from the varnish group"
1179 echo " gpasswd -d netdata varnish"
1182 getent group haproxy > /dev/null
1183 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1186 echo "You may also want to remove the netdata user from the haproxy group"
1188 echo " gpasswd -d netdata haproxy"
1191 getent group adm > /dev/null
1192 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_ADM}" = "1" ]
1195 echo "You may also want to remove the netdata user from the adm group"
1197 echo " gpasswd -d netdata adm"
1202 chmod 750 netdata-uninstaller.sh
1204 # -----------------------------------------------------------------------------
1205 progress "Basic netdata instructions"
1209 netdata by default netdata listens on all IPs on port ${NETDATA_PORT},
1210 so you can access it with:
1212 http://this.machine.ip:${NETDATA_PORT}/
1214 To stop netdata, just kill it, with:
1216 $(printf "${COLOR_YELLOW}${COLOR_BOLD}killall netdata${COLOR_RESET}")
1218 To start it, just run it:
1220 $(printf "${COLOR_YELLOW}${COLOR_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${COLOR_RESET}")
1224 echo >&2 -e "Uninstall script generated: ${COLOR_YELLOW}${COLOR_BOLD}./netdata-uninstaller.sh${COLOR_RESET}"
1228 cat >netdata-updater.sh.new <<REINSTALL
1232 [ "\${1}" = "-f" ] && force=1
1234 export PATH="\${PATH}:${PATH}"
1235 export CFLAGS="${CFLAGS}"
1237 INSTALL_UID="${UID}"
1238 if [ "\${INSTALL_UID}" != "\${UID}" ]
1240 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1244 # make sure we cd to the working directory
1245 cd "${REINSTALL_PWD}" || exit 1
1247 # make sure there is .git here
1248 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1250 # signal netdata to start saving its database
1251 # this is handy if your database is big
1252 pids=\$(pidof netdata)
1253 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1258 # we are running on a terminal
1259 # open fd 3 and send it to stderr
1263 # create a temporary file for the log
1264 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1265 # open fd 3 and send it to tmp
1270 echo >&3 "\$(date) : INFO: " "\${@}"
1278 echo >&3 "\$(date) : ERROR: " "\${@}"
1281 # this is what we will do if it fails (head-less only)
1283 error "FAILED TO UPDATE NETDATA : \${1}"
1285 if [ ! -z "\${tmp}" ]
1293 get_latest_commit_id() {
1295 grep ^commit 2>&3 |\\
1297 cut -d ' ' -f 2 2>&3
1301 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1307 info "Updating netdata source from github..."
1309 last_commit="\$(get_latest_commit_id)"
1310 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1312 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1314 new_commit="\$(get_latest_commit_id)"
1315 if [ \${force} -eq 0 ]
1317 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1318 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1320 elif [ \${force} -eq 0 ]
1322 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1326 info "Re-installing netdata..."
1327 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1329 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1333 # the installer updates this script - so we run and exit in a single line
1335 ###############################################################################
1336 ###############################################################################
1338 chmod 755 netdata-updater.sh.new
1339 mv -f netdata-updater.sh.new netdata-updater.sh
1340 echo >&2 -e "Update script generated : ${COLOR_YELLOW}${COLOR_BOLD}./netdata-updater.sh${COLOR_RESET}"
1341 elif [ -f "netdata-updater.sh" ]
1343 rm "netdata-updater.sh"
1346 # -----------------------------------------------------------------------------
1348 progress "We are done!"
1350 if [ ${started} -eq 1 ]
1352 netdata_banner "is installed and running now!"
1354 netdata_banner "is installed now!"
1357 echo >&2 " enjoy real-time performance and health monitoring..."