3 # reload the user profile
4 [ -f /etc/profile ] && . /etc/profile
6 # fix PKG_CHECK_MODULES error
7 if [ -d /usr/share/aclocal ]
9 ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
16 # you can set CFLAGS before running installer
17 CFLAGS="${CFLAGS--O3}"
19 # keep a log of this command
20 printf "\n# " >>netdata-installer.log
21 date >>netdata-installer.log
22 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
23 printf "%q " "$0" "${@}" >>netdata-installer.log
24 printf "\n" >>netdata-installer.log
35 ${ME} <installer options>
37 Valid <installer options> are:
39 --install /PATH/TO/INSTALL
41 If your give: --install /opt
42 netdata will be installed in /opt/netdata
46 Do not (re)start netdata.
51 Do not wait for the user to press ENTER.
52 Start immediately building it.
55 --libs-are-really-here
57 If you get errors about missing zlib,
58 or libuuid but you know it is available,
59 you have a broken pkg-config.
60 Use this option to allow it continue
61 without checking pkg-config.
63 Netdata will by default be compiled with gcc optimization -O3
64 If you need to pass different CFLAGS, use something like this:
66 CFLAGS="<gcc options>" ${ME} <installer options>
68 For the installer to complete successfully, you will need
69 these packages installed:
71 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
72 uuid-dev (or libuuid-devel)
74 For the plugins, you will at least need:
83 if [ "$1" = "--install" ]
85 NETDATA_PREFIX="${2}/netdata"
87 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
91 elif [ "$1" = "--dont-start-it" ]
95 elif [ "$1" = "--dont-wait" ]
99 elif [ "$1" = "--help" -o "$1" = "-h" ]
106 echo >&2 "I cannot understand option '$1'."
115 Nice to see you are giving it a try!
117 You are about to build and install netdata to your system.
119 It will be installed at these locations:
121 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
122 - config files at ${NETDATA_PREFIX}/etc/netdata
123 - web files at ${NETDATA_PREFIX}/usr/share/netdata
124 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
125 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
126 - db files at ${NETDATA_PREFIX}/var/lib/netdata
127 - log files at ${NETDATA_PREFIX}/var/log/netdata
128 - pid file at ${NETDATA_PREFIX}/var/run
130 This installer allows you to change the installation path.
131 Press Control-C and run the same command with --help for help.
135 if [ "${UID}" -ne 0 ]
137 if [ -z "${NETDATA_PREFIX}" ]
139 cat <<-NONROOTNOPREFIX
141 Sorry! This will fail!
143 You are attempting to install netdata as non-root, but you plan to install it
146 Please set an installation prefix, like this:
148 $0 ${@} --install /tmp
150 or, run the installer as root:
154 We suggest to install it as root, or certain data collectors will not be able
155 to work. Netdata drops root privileges when running. So, if you plan to keep
156 it, install it as root to get the full functionality.
165 You are about to install netdata as a non-root user.
166 Netdata will work, but a few data collection modules that
167 require root access will fail.
169 If you installing permanently on your system, run the
179 if [ "$(type autoreconf 2> /dev/null)" ]
187 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
188 eval $maj=\$1 $min=\$2
190 autoconf_maj_min AMAJ AMIN
195 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
199 echo "Found autotools $AMAJ.$AMIN"
202 echo "No autotools found"
205 if [ ! "$have_autotools" ]
209 echo "Will skip autoreconf step"
213 -------------------------------------------------------------------------------
214 autotools 2.60 or later is required
216 Sorry, you do not seem to have autotools 2.60 or later, which is
217 required to build from the git sources of netdata.
219 You can either install a suitable version of autotools and automake
220 or download a netdata package which does not have these dependencies.
222 Source packages where autotools have already been run are available
224 https://firehol.org/download/netdata/
226 The unsigned/master folder tracks the head of the git tree and released
227 packages are also available.
233 if [ ${DONOTWAIT} -eq 0 ]
235 if [ ! -z "${NETDATA_PREFIX}" ]
237 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
239 read -p "Press ENTER to build and install netdata to your system > "
246 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248 Sorry! NetData failed to build...
250 You many need to check these:
252 1. The package uuid-dev (or libuuid-devel) has to be installed.
254 If your system cannot find libuuid, although it is installed
255 run me with the option: --libs-are-really-here
257 2. The package zlib1g-dev (or zlib-devel) has to be installed.
259 If your system cannot find zlib, although it is installed
260 run me with the option: --libs-are-really-here
262 3. You need basic build tools installed, like:
264 gcc make autoconf automake pkg-config
266 Autoconf version 2.60 or higher is required.
268 If you still cannot get it to build, ask for help at github:
270 https://github.com/firehol/netdata/issues
279 printf >>netdata-installer.log "# "
280 printf >>netdata-installer.log "%q " "${@}"
281 printf >>netdata-installer.log " ... "
284 printf >&2 ":-----------------------------------------------------------------------------\n"
285 printf >&2 "Running command:\n"
287 printf >&2 "%q " "${@}"
295 printf >>netdata-installer.log "FAILED!\n"
297 printf >>netdata-installer.log "OK\n"
303 if [ ${LIBS_ARE_HERE} -eq 1 ]
306 echo >&2 "ok, assuming libs are really installed."
307 export ZLIB_CFLAGS=" "
308 export ZLIB_LIBS="-lz"
309 export UUID_CFLAGS=" "
310 export UUID_LIBS="-luuid"
313 trap build_error EXIT
315 if [ "$have_autotools" ]
317 run ./autogen.sh || exit 1
321 --prefix="${NETDATA_PREFIX}/usr" \
322 --sysconfdir="${NETDATA_PREFIX}/etc" \
323 --localstatedir="${NETDATA_PREFIX}/var" \
324 --with-zlib --with-math --with-user=netdata \
325 CFLAGS="${CFLAGS}" || exit 1
327 # remove the build_error hook
330 if [ -f src/netdata ]
332 echo >&2 "Cleaning a possibly old compilation ..."
336 echo >&2 "Compiling netdata ..."
339 # backup user configurations
340 installer_backup_suffix="${PID}.${RANDOM}"
341 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
345 cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
347 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
349 rm -f "${x}.installer_backup.${installer_backup_suffix}"
353 echo >&2 "Installing netdata ..."
354 run make install || exit 1
356 # restore user configurations
357 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
359 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
361 cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
362 rm -f "${x}.installer_backup.${installer_backup_suffix}"
366 NETDATA_ADDED_TO_DOCKER=0
369 getent group netdata > /dev/null
372 echo >&2 "Adding netdata user group ..."
373 run groupadd -r netdata
376 getent passwd netdata > /dev/null
379 echo >&2 "Adding netdata user account ..."
380 run useradd -r -g netdata -c netdata -s $(which nologin || echo '/bin/false') -d / netdata
383 getent group docker > /dev/null
386 # find the users in the docker group
387 docker=$(getent group docker | cut -d ':' -f 4)
388 if [[ ",${docker}," =~ ,netdata, ]]
390 # netdata is already there
393 # netdata is not in docker group
394 echo >&2 "Adding netdata user to the docker group (needed to get container names) ..."
395 run usermod -a -G docker netdata
397 # let the uninstall script know
398 NETDATA_ADDED_TO_DOCKER=1
401 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
403 echo >&2 "Adding netdata logrotate configuration ..."
404 run cp system/netdata.logrotate /etc/logrotate.d/netdata
409 # -----------------------------------------------------------------------------
410 # load options from the configuration file
412 # create an empty config if it does not exist
413 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
415 # function to extract values from the config file
417 local key="${1}" value="${2}" line=
419 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
421 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
422 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
430 [ ! "${UID}" = "0" ] && defuser="${USER}"
431 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
433 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
434 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
438 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
442 NETDATA_PORT="$( config_option "port" ${defport} )"
445 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
446 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
447 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
448 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
449 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
450 NETDATA_BIND="$( config_option "bind socket to IP" "*" )"
451 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
454 # -----------------------------------------------------------------------------
455 # prepare the directories
457 # this is needed if NETDATA_PREFIX is not empty
458 if [ ! -d "${NETDATA_RUN_DIR}" ]
460 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
464 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
465 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}" "${NETDATA_LIB_DIR}"
469 echo >&2 "Creating directory '${x}'"
470 run mkdir -p "${x}" || exit 1
475 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
477 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}..."
479 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
483 run chmod 0755 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
488 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
489 run chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
490 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
493 # fix apps.plugin to be setuid to root
494 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
495 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
499 # -----------------------------------------------------------------------------
500 # check if we can re-start netdata
502 if [ ${DONOTSTART} -eq 1 ]
504 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
506 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
507 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
509 if [ "${UID}" -eq 0 ]
511 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
513 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
515 echo >&2 "OK. It is now installed and ready."
519 # -----------------------------------------------------------------------------
520 # stop a running netdata
523 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
524 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
528 stop_netdata_on_pid() {
529 local pid="$1" ret=0 count=0
531 isnetdata $pid || return 0
533 printf >&2 "Stopping netdata on pid $pid ..."
534 while [ ! -z "$pid" -a $ret -eq 0 ]
538 echo >&2 "Cannot stop the running netdata on pid $pid."
542 count=$(( count + 1 ))
544 run kill $pid 2>/dev/null
547 test $ret -eq 0 && printf >&2 "." && sleep 2
553 echo >&2 "SORRY! CANNOT STOP netdata ON PID $pid !"
557 echo >&2 "netdata on pid $pid stopped."
564 echo >&2 "Stopping a (possibly) running netdata..."
566 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
567 $(cat /var/run/netdata.pid 2>/dev/null) \
568 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
569 $(pidof netdata 2>/dev/null)
571 stop_netdata_on_pid $p
575 # -----------------------------------------------------------------------------
576 # check netdata for systemd
579 # if the directory /etc/systemd/system does not exit, it is not systemd
580 [ ! -d /etc/systemd/system ] && return 1
582 # if pid 1 is systemd, it is systemd
583 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
585 # if systemd is running, it is systemd
586 pidof systemd >/dev/null 2>&1 && return 0
588 # else, it is not systemd
593 if [ "${UID}" -eq 0 ]
598 # systemd is running on this system
600 if [ ! -f /etc/systemd/system/netdata.service ]
602 echo >&2 "Installing systemd service..."
603 run cp system/netdata.service /etc/systemd/system/netdata.service && \
604 run systemctl daemon-reload && \
605 run systemctl enable netdata
607 run service netdata stop
611 run service netdata restart && started=1
614 if [ ${started} -eq 0 ]
616 # check if we can use the system service
617 run service netdata stop
619 run service netdata restart && started=1
620 if [ ${started} -eq 0 ]
622 run service netdata start && started=1
627 if [ ${started} -eq 0 ]
629 # still not started...
633 echo >&2 "Starting netdata..."
634 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
638 echo >&2 "SORRY! FAILED TO START NETDATA!"
641 echo >&2 "OK. NetData Started!"
647 # -----------------------------------------------------------------------------
648 # save a config file, if it is not already there
650 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
653 echo >&2 "-------------------------------------------------------------------------------"
655 echo >&2 "Downloading default configuration from netdata..."
658 # remove a possibly obsolete download
659 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
661 # disable a proxy to get data from the local netdata
666 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
670 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
672 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
676 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
678 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
679 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
681 if [ "${UID}" -eq 0 ]
683 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
685 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
687 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
688 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
692 # -----------------------------------------------------------------------------
695 ksm_is_available_but_disabled() {
698 -------------------------------------------------------------------------------
699 Memory de-duplication instructions
701 You have kernel memory de-duper (called Kernel Same-page Merging,
702 or KSM) available, but it is not currently enabled.
706 echo 1 >/sys/kernel/mm/ksm/run
707 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
709 If you enable it, you will save 40-60% of netdata memory.
714 ksm_is_not_available() {
717 -------------------------------------------------------------------------------
718 Memory de-duplication not present in your kernel
720 It seems you do not have kernel memory de-duper (called Kernel Same-page
721 Merging, or KSM) available.
723 To enable it, you need a kernel built with CONFIG_KSM=y
725 If you can have it, you will save 40-60% of netdata memory.
730 if [ -f "/sys/kernel/mm/ksm/run" ]
732 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
734 ksm_is_available_but_disabled
740 # -----------------------------------------------------------------------------
741 # Check for version.txt
743 if [ ! -s web/version.txt ]
747 -------------------------------------------------------------------------------
748 Version update check warning
750 The way you downloaded netdata, we cannot find its version. This means the
751 Update check on the dashboard, will not work.
753 If you want to have version update check, please re-install it
754 following the procedure in:
756 https://github.com/firehol/netdata/wiki/Installation
761 # -----------------------------------------------------------------------------
762 # apps.plugin warning
764 if [ "${UID}" -ne 0 ]
766 cat <<-SETUID_WARNING
768 -------------------------------------------------------------------------------
769 apps.plugin needs privileges
771 Since you have installed netdata as a normal user, to have apps.plugin collect
772 all the needed data, you have to give it the access rights it needs, by running
773 either of the following sets of commands:
775 To run apps.plugin with escalated capabilities:
777 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
778 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
779 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
781 or, to run apps.plugin as root:
783 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
784 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
786 apps.plugin is performing a hard-coded function of data collection for all
787 running processes. It cannot be instructed from the netdata daemon to perform
788 any task, so it is pretty safe to do this.
793 # -----------------------------------------------------------------------------
794 # Keep un-install info
796 cat >netdata-uninstaller.sh <<-UNINSTALL
799 # this script will uninstall netdata
801 if [ "\$1" != "--force" ]
803 echo >&2 "This script will REMOVE netdata from your system."
804 echo >&2 "Run it again with --force to do it."
808 echo >&2 "Stopping a possibly running netdata..."
809 for p in \$(pidof netdata); do kill \$p; done
813 if [ ! -z "\$1" -a -d "\$1" ]
816 echo "Deleting directory '\$1' ..."
821 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
823 # installation prefix was given
825 deletedir "${NETDATA_PREFIX}"
828 # installation prefix was NOT given
830 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
832 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
833 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
836 deletedir "${NETDATA_PREFIX}/etc/netdata"
837 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
838 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
839 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
840 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
841 deletedir "${NETDATA_PREFIX}/var/log/netdata"
844 if [ -f /etc/logrotate.d/netdata ]
846 echo "Deleting /etc/logrotate.d/netdata ..."
847 rm -i /etc/logrotate.d/netdata
850 if [ -f /etc/systemd/system/netdata.service ]
852 echo "Deleting /etc/systemd/system/netdata.service ..."
853 rm -i /etc/systemd/system/netdata.service
856 getent passwd netdata > /dev/null
860 echo "You may also want to remove the user netdata"
862 echo " userdel netdata"
865 getent group netdata > /dev/null
869 echo "You may also want to remove the group netdata"
871 echo " groupdel netdata"
874 getent group docker > /dev/null
875 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
878 echo "You may also want to remove the netdata user from the docker group"
880 echo " gpasswd -d netdata docker"
884 chmod 750 netdata-uninstaller.sh
886 # -----------------------------------------------------------------------------
888 if [ "${NETDATA_BIND}" = "*" ]
892 access="${NETDATA_BIND}"
898 -------------------------------------------------------------------------------
900 OK. NetData is installed and it is running (listening to ${NETDATA_BIND}:${NETDATA_PORT}).
902 -------------------------------------------------------------------------------
904 INFO: Command line options changed. -pidfile, -nd and -ch are deprecated.
905 If you use custom startup scripts, please run netdata -h to see the
906 corresponding options and update your scripts.
908 Hit http://${access}:${NETDATA_PORT}/ from your browser.
910 To stop netdata, just kill it, with:
914 To start it, just run it:
916 ${NETDATA_PREFIX}/usr/sbin/netdata
922 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"