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 # you can set CFLAGS before running installer
19 CFLAGS="${CFLAGS--O3}"
21 # keep a log of this command
22 printf "\n# " >>netdata-installer.log
23 date >>netdata-installer.log
24 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
25 printf "%q " "$0" "${@}" >>netdata-installer.log
26 printf "\n" >>netdata-installer.log
28 REINSTALL_PWD="${PWD}"
29 REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
33 l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
34 l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
35 l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
37 netdata="netdata" start end msg="${*}"
39 [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
40 [ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
42 start="$(( ${#l2} / 2 - 4 ))"
43 [ $(( start + ${#msg} + 4 )) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
44 end=$(( ${start} + ${#msg} + 4 ))
48 echo >&2 "${l2:0:start}${sp:0:2}${netdata}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}"
49 echo >&2 "${l3:0:start}${sp:0:2}${msg}${sp:0:2}${l3:end:$((${#l2} - end))}"
54 service="$(which service 2>/dev/null || command -v service 2>/dev/null)"
55 systemctl="$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)"
57 local cmd="${1}" action="${2}"
59 if [ ! -z "${service}" ]
61 run "${service}" "${cmd}" "${action}"
63 elif [ ! -z "${systemctl}" ]
65 run "${systemctl}" "${action}" "${cmd}"
78 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 -O3
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 "${x}:${s}"
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 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 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 to install it
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 not be able
246 to work. Netdata drops root privileges when running. So, if you plan to keep
247 it, install it as root to get the full functionality.
256 You are about to install netdata as a non-root user.
257 Netdata will work, but a few data collection modules that
258 require root access will fail.
260 If you installing permanently on your system, run the
270 if [ "$(type autoreconf 2> /dev/null)" ]
278 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
279 eval $maj=\$1 $min=\$2
281 autoconf_maj_min AMAJ AMIN
286 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
290 echo "Found autotools $AMAJ.$AMIN"
293 echo "No autotools found"
296 if [ ! "$have_autotools" ]
300 echo "Will skip autoreconf step"
302 banner "autotools v2.60 required"
305 -------------------------------------------------------------------------------
306 autotools 2.60 or later is required
308 Sorry, you do not seem to have autotools 2.60 or later, which is
309 required to build from the git sources of netdata.
311 You can either install a suitable version of autotools and automake
312 or download a netdata package which does not have these dependencies.
314 Source packages where autotools have already been run are available
316 https://firehol.org/download/netdata/
318 The unsigned/master folder tracks the head of the git tree and released
319 packages are also available.
325 if [ ${DONOTWAIT} -eq 0 ]
327 if [ ! -z "${NETDATA_PREFIX}" ]
329 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
331 read -p "Press ENTER to build and install netdata to your system > "
336 banner "sorry, it failed to build..."
339 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
341 Sorry! netdata failed to build...
343 You many need to check these:
345 1. The package uuid-dev (or libuuid-devel) has to be installed.
347 If your system cannot find libuuid, although it is installed
348 run me with the option: --libs-are-really-here
350 2. The package zlib1g-dev (or zlib-devel) has to be installed.
352 If your system cannot find zlib, although it is installed
353 run me with the option: --libs-are-really-here
355 3. You need basic build tools installed, like:
357 gcc make autoconf automake pkg-config
359 Autoconf version 2.60 or higher is required.
361 If you still cannot get it to build, ask for help at github:
363 https://github.com/firehol/netdata/issues
372 printf >>netdata-installer.log "# "
373 printf >>netdata-installer.log "%q " "${@}"
374 printf >>netdata-installer.log " ... "
377 printf >&2 ":-----------------------------------------------------------------------------\n"
378 printf >&2 "Running command:\n"
380 printf >&2 "%q " "${@}"
388 printf >>netdata-installer.log "FAILED!\n"
390 printf >>netdata-installer.log "OK\n"
396 if [ ${LIBS_ARE_HERE} -eq 1 ]
399 echo >&2 "ok, assuming libs are really installed."
400 export ZLIB_CFLAGS=" "
401 export ZLIB_LIBS="-lz"
402 export UUID_CFLAGS=" "
403 export UUID_LIBS="-luuid"
406 trap build_error EXIT
408 if [ "$have_autotools" ]
410 run ./autogen.sh || exit 1
414 --prefix="${NETDATA_PREFIX}/usr" \
415 --sysconfdir="${NETDATA_PREFIX}/etc" \
416 --localstatedir="${NETDATA_PREFIX}/var" \
417 --with-zlib --with-math --with-user=netdata \
418 CFLAGS="${CFLAGS}" || exit 1
420 # remove the build_error hook
423 if [ -f src/netdata ]
425 echo >&2 "Cleaning a possibly old compilation ..."
429 echo >&2 "Compiling netdata ..."
432 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
434 declare -A configs_signatures=()
435 if [ -f "configs.signatures" ]
437 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
441 # migrate existing configuration files
442 # for node.d and charts.d
443 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
445 # the configuration directory exists
447 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
449 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
452 # move the charts.d config files
453 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
455 for y in "" ".old" ".orig"
457 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
459 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
464 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
466 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
469 # move the node.d config files
470 for x in named sma_webbox snmp
472 for y in "" ".old" ".orig"
474 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
476 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
482 # backup user configurations
483 installer_backup_suffix="${PID}.${RANDOM}"
484 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
488 # make a backup of the configuration file
489 cp -p "${x}" "${x}.old"
491 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
493 # we don't have md5sum - keep it
494 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
496 # find it relative filename
497 f="${x/*\/etc\/netdata\//}"
500 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
503 if [ -f "conf.d/${f}" ]
505 cp "conf.d/${f}" "${x}.orig"
508 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
510 if [ "${configs_signatures[${md5}]}" = "${f}" ]
512 # it is a stock version - don't keep it
513 echo >&2 "File '${x}' is stock version."
515 # edited by user - keep it
516 echo >&2 "File '${x}' has been edited by user."
517 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
520 echo >&2 "File '${x}' cannot be check for custom edits."
521 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
525 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
527 rm -f "${x}.installer_backup.${installer_backup_suffix}"
531 echo >&2 "Installing netdata ..."
532 run make install || exit 1
534 # restore user configurations
535 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
537 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
539 cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
540 rm -f "${x}.installer_backup.${installer_backup_suffix}"
544 NETDATA_ADDED_TO_DOCKER=0
547 getent group netdata > /dev/null
550 echo >&2 "Adding netdata user group ..."
551 run groupadd -r netdata
554 getent passwd netdata > /dev/null
557 echo >&2 "Adding netdata user account ..."
558 run useradd -r -g netdata -c netdata -s $(which nologin || echo '/bin/false') -d / netdata
561 getent group docker > /dev/null
564 # find the users in the docker group
565 docker=$(getent group docker | cut -d ':' -f 4)
566 if [[ ",${docker}," =~ ,netdata, ]]
568 # netdata is already there
571 # netdata is not in docker group
572 echo >&2 "Adding netdata user to the docker group (needed to get container names) ..."
573 run usermod -a -G docker netdata
575 # let the uninstall script know
576 NETDATA_ADDED_TO_DOCKER=1
579 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
581 echo >&2 "Adding netdata logrotate configuration ..."
582 run cp system/netdata.logrotate /etc/logrotate.d/netdata
587 # -----------------------------------------------------------------------------
588 # load options from the configuration file
590 # create an empty config if it does not exist
591 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
593 # function to extract values from the config file
595 local key="${1}" value="${2}" line=
597 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
599 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
600 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
608 [ ! "${UID}" = "0" ] && defuser="${USER}"
609 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
611 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
612 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
616 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
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 # prepare the directories
643 # this is needed if NETDATA_PREFIX is not empty
644 if [ ! -d "${NETDATA_RUN_DIR}" ]
646 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
650 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
651 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}" "${NETDATA_LIB_DIR}" "${NETDATA_CONF_DIR}/python.d" "${NETDATA_CONF_DIR}/charts.d" "${NETDATA_CONF_DIR}/node.d"
655 echo >&2 "Creating directory '${x}'"
656 run mkdir -p "${x}" || exit 1
661 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
663 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}..."
665 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
669 run chmod 0755 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
674 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
675 run chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
676 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
679 # fix apps.plugin to be setuid to root
680 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
681 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
685 # -----------------------------------------------------------------------------
686 # check if we can re-start netdata
688 if [ ${DONOTSTART} -eq 1 ]
690 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
692 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
693 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
695 if [ "${UID}" -eq 0 ]
697 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
699 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
701 banner "is installed now!"
702 echo >&2 " enjoy real-time performance and health monitoring..."
706 # -----------------------------------------------------------------------------
707 # stop a running netdata
710 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
711 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
715 stop_netdata_on_pid() {
716 local pid="$1" ret=0 count=0
718 isnetdata $pid || return 0
720 printf >&2 "Stopping netdata on pid $pid ..."
721 while [ ! -z "$pid" -a $ret -eq 0 ]
725 echo >&2 "Cannot stop the running netdata on pid $pid."
729 count=$(( count + 1 ))
731 run kill $pid 2>/dev/null
734 test $ret -eq 0 && printf >&2 "." && sleep 2
740 echo >&2 "SORRY! CANNOT STOP netdata ON PID $pid !"
744 echo >&2 "netdata on pid $pid stopped."
751 echo >&2 "Stopping a (possibly) running netdata..."
753 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
754 $(cat /var/run/netdata.pid 2>/dev/null) \
755 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
756 $(pidof netdata 2>/dev/null)
758 stop_netdata_on_pid $p
762 # -----------------------------------------------------------------------------
763 # check netdata for systemd
766 # if the directory /etc/systemd/system does not exit, it is not systemd
767 [ ! -d /etc/systemd/system ] && return 1
769 # if pid 1 is systemd, it is systemd
770 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
772 # if systemd is running, it is systemd
773 pidof systemd >/dev/null 2>&1 && return 0
775 # else, it is not systemd
780 if [ "${UID}" -eq 0 ]
785 # systemd is running on this system
787 if [ ! -f /etc/systemd/system/netdata.service ]
789 echo >&2 "Installing systemd service..."
790 run cp system/netdata.service /etc/systemd/system/netdata.service && \
791 run systemctl daemon-reload && \
792 run systemctl enable netdata
798 service netdata restart && started=1
801 if [ ${started} -eq 0 ]
803 # check if we can use the system service
806 service netdata restart && started=1
807 if [ ${started} -eq 0 ]
809 service netdata start && started=1
814 if [ ${started} -eq 0 ]
816 # still not started...
820 echo >&2 "Starting netdata..."
821 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
825 echo >&2 "SORRY! FAILED TO START NETDATA!"
828 echo >&2 "OK. NetData Started!"
834 # -----------------------------------------------------------------------------
835 # save a config file, if it is not already there
837 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
840 echo >&2 "-------------------------------------------------------------------------------"
842 echo >&2 "Downloading default configuration from netdata..."
845 # remove a possibly obsolete download
846 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
848 # disable a proxy to get data from the local netdata
853 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
857 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
859 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
863 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
865 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
866 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
868 if [ "${UID}" -eq 0 ]
870 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
872 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
874 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
875 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
879 # -----------------------------------------------------------------------------
882 ksm_is_available_but_disabled() {
885 -------------------------------------------------------------------------------
886 Memory de-duplication instructions
888 You have kernel memory de-duper (called Kernel Same-page Merging,
889 or KSM) available, but it is not currently enabled.
893 echo 1 >/sys/kernel/mm/ksm/run
894 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
896 If you enable it, you will save 40-60% of netdata memory.
901 ksm_is_not_available() {
904 -------------------------------------------------------------------------------
905 Memory de-duplication not present in your kernel
907 It seems you do not have kernel memory de-duper (called Kernel Same-page
908 Merging, or KSM) available.
910 To enable it, you need a kernel built with CONFIG_KSM=y
912 If you can have it, you will save 40-60% of netdata memory.
917 if [ -f "/sys/kernel/mm/ksm/run" ]
919 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
921 ksm_is_available_but_disabled
927 # -----------------------------------------------------------------------------
928 # Check for version.txt
930 if [ ! -s web/version.txt ]
934 -------------------------------------------------------------------------------
935 Version update check warning
937 The way you downloaded netdata, we cannot find its version. This means the
938 Update check on the dashboard, will not work.
940 If you want to have version update check, please re-install it
941 following the procedure in:
943 https://github.com/firehol/netdata/wiki/Installation
948 # -----------------------------------------------------------------------------
949 # apps.plugin warning
951 if [ "${UID}" -ne 0 ]
955 -------------------------------------------------------------------------------
956 apps.plugin needs privileges
958 Since you have installed netdata as a normal user, to have apps.plugin collect
959 all the needed data, you have to give it the access rights it needs, by running
960 either of the following sets of commands:
962 To run apps.plugin with escalated capabilities:
964 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
965 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
966 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
968 or, to run apps.plugin as root:
970 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
971 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
973 apps.plugin is performing a hard-coded function of data collection for all
974 running processes. It cannot be instructed from the netdata daemon to perform
975 any task, so it is pretty safe to do this.
980 # -----------------------------------------------------------------------------
981 # Keep un-install info
983 cat >netdata-uninstaller.sh <<UNINSTALL
986 # this script will uninstall netdata
988 if [ "\$1" != "--force" ]
990 echo >&2 "This script will REMOVE netdata from your system."
991 echo >&2 "Run it again with --force to do it."
995 echo >&2 "Stopping a possibly running netdata..."
996 for p in \$(pidof netdata); do kill \$p; done
1000 if [ ! -z "\$1" -a -d "\$1" ]
1003 echo "Deleting directory '\$1' ..."
1008 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1010 # installation prefix was given
1012 deletedir "${NETDATA_PREFIX}"
1015 # installation prefix was NOT given
1017 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1019 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1020 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1023 deletedir "${NETDATA_PREFIX}/etc/netdata"
1024 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1025 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1026 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1027 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1028 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1031 if [ -f /etc/logrotate.d/netdata ]
1033 echo "Deleting /etc/logrotate.d/netdata ..."
1034 rm -i /etc/logrotate.d/netdata
1037 if [ -f /etc/systemd/system/netdata.service ]
1039 echo "Deleting /etc/systemd/system/netdata.service ..."
1040 rm -i /etc/systemd/system/netdata.service
1043 getent passwd netdata > /dev/null
1047 echo "You may also want to remove the user netdata"
1049 echo " userdel netdata"
1052 getent group netdata > /dev/null
1056 echo "You may also want to remove the group netdata"
1058 echo " groupdel netdata"
1061 getent group docker > /dev/null
1062 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1065 echo "You may also want to remove the netdata user from the docker group"
1067 echo " gpasswd -d netdata docker"
1071 chmod 750 netdata-uninstaller.sh
1073 # -----------------------------------------------------------------------------
1078 -------------------------------------------------------------------------------
1080 OK. NetData is installed and it is running.
1082 -------------------------------------------------------------------------------
1084 By default netdata listens on all IPs on port ${NETDATA_PORT},
1085 so you can access it with:
1087 http://this.machine.ip:${NETDATA_PORT}/
1089 To stop netdata, just kill it, with:
1093 To start it, just run it:
1095 ${NETDATA_PREFIX}/usr/sbin/netdata
1099 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1103 cat >netdata-updater.sh.new <<REINSTALL
1107 [ "\${1}" = "-f" ] && force=1
1109 export PATH="\${PATH}:${PATH}"
1110 export CFLAGS="${CFLAGS}"
1112 INSTALL_UID="${UID}"
1113 if [ "\${INSTALL_UID}" != "\${UID}" ]
1115 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1119 # make sure we cd to the working directory
1120 cd "${REINSTALL_PWD}" || exit 1
1122 # make sure there is .git here
1123 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1125 # signal netdata to start saving its database
1126 # this is handy if your database is big
1127 pids=\$(pidof netdata)
1128 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1133 # we are running on a terminal
1134 # open fd 3 and send it to stderr
1138 # create a temporary file for the log
1139 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1140 # open fd 3 and send it to tmp
1145 echo >&3 "\$(date) : INFO: " "\${@}"
1153 echo >&3 "\$(date) : ERROR: " "\${@}"
1156 # this is what we will do if it fails (head-less only)
1158 error "FAILED TO UPDATE NETDATA : \${1}"
1160 if [ ! -z "\${tmp}" ]
1168 get_latest_commit_id() {
1170 grep ^commit 2>&3 |\\
1172 cut -d ' ' -f 2 2>&3
1176 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1182 info "Updating netdata source from github..."
1184 last_commit="\$(get_latest_commit_id)"
1185 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1187 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1189 new_commit="\$(get_latest_commit_id)"
1190 if [ \${force} -eq 0 ]
1192 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1193 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1195 elif [ \${force} -eq 0 ]
1197 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1201 info "Re-installing netdata..."
1202 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1204 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1208 # the installer updates this script - so we run and exit in a single line
1210 ###############################################################################
1211 ###############################################################################
1213 chmod 755 netdata-updater.sh.new
1214 mv -f netdata-updater.sh.new netdata-updater.sh
1215 echo >&2 "Update script generated : ./netdata-updater.sh"
1216 elif [ -f "netdata-updater.sh" ]
1218 rm "netdata-updater.sh"
1221 banner "is installed and running now!"
1222 echo >&2 " enjoy real-time performance and health monitoring..."