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.
56 If you get errors about missing zlib,
57 but you know it is available,
58 you have a broken pkg-config.
59 Use this option to allow it continue
60 without checking pkg-config.
62 Netdata will by default be compiled with gcc optimization -O3
63 If you need to pass different CFLAGS, use something like this:
65 CFLAGS="<gcc options>" ${ME} <installer options>
67 For the installer to complete successfully, you will need
68 these packages installed:
70 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
71 uuid-dev (or libuuid-devel)
73 For the plugins, you will at least need:
82 if [ "$1" = "--install" ]
84 NETDATA_PREFIX="${2}/netdata"
86 elif [ "$1" = "--zlib-is-really-here" ]
90 elif [ "$1" = "--dont-start-it" ]
94 elif [ "$1" = "--dont-wait" ]
98 elif [ "$1" = "--help" -o "$1" = "-h" ]
105 echo >&2 "I cannot understand option '$1'."
114 Nice to see you are giving it a try!
116 You are about to build and install netdata to your system.
118 It will be installed at these locations:
120 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
121 - config files at ${NETDATA_PREFIX}/etc/netdata
122 - web files at ${NETDATA_PREFIX}/usr/share/netdata
123 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
124 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
125 - db files at ${NETDATA_PREFIX}/var/lib/netdata
126 - log files at ${NETDATA_PREFIX}/var/log/netdata
127 - pid file at ${NETDATA_PREFIX}/var/run
129 This installer allows you to change the installation path.
130 Press Control-C and run the same command with --help for help.
134 if [ "${UID}" -ne 0 ]
136 if [ -z "${NETDATA_PREFIX}" ]
138 cat <<-NONROOTNOPREFIX
140 Sorry! This will fail!
142 You are attempting to install netdata as non-root, but you plan to install it
145 Please set an installation prefix, like this:
147 $0 ${@} --install /tmp
149 or, run the installer as root:
153 We suggest to install it as root, or certain data collectors will not be able
154 to work. Netdata drops root privileges when running. So, if you plan to keep
155 it, install it as root to get the full functionality.
164 You are about to install netdata as a non-root user.
165 Netdata will work, but a few data collection modules that
166 require root access will fail.
168 If you installing permanently on your system, run the
178 if [ "$(type autoreconf 2> /dev/null)" ]
186 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
187 eval $maj=\$1 $min=\$2
189 autoconf_maj_min AMAJ AMIN
194 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
198 echo "Found autotools $AMAJ.$AMIN"
201 echo "No autotools found"
204 if [ ! "$have_autotools" ]
208 echo "Will skip autoreconf step"
212 -------------------------------------------------------------------------------
213 autotools 2.60 or later is required
215 Sorry, you do not seem to have autotools 2.60 or later, which is
216 required to build from the git sources of netdata.
218 You can either install a suitable version of autotools and automake
219 or download a netdata package which does not have these dependencies.
221 Source packages where autotools have already been run are available
223 https://firehol.org/download/netdata/
225 The unsigned/master folder tracks the head of the git tree and released
226 packages are also available.
232 if [ ${DONOTWAIT} -eq 0 ]
234 if [ ! -z "${NETDATA_PREFIX}" ]
236 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
238 read -p "Press ENTER to build and install netdata to your system > "
245 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
247 Sorry! NetData failed to build...
249 You many need to check these:
251 1. The package uuid-dev (or libuuid-devel) has to be installed.
253 2. The package zlib1g-dev (or zlib-devel) has to be installed.
255 If your system cannot find ZLIB, although it is installed
256 run me with the option: --zlib-is-really-here
258 3. You need basic build tools installed, like:
260 gcc make autoconf automake pkg-config
262 Autoconf version 2.60 or higher is required.
264 If you still cannot get it to build, ask for help at github:
266 https://github.com/firehol/netdata/issues
275 printf >>netdata-installer.log "# "
276 printf >>netdata-installer.log "%q " "${@}"
277 printf >>netdata-installer.log " ... "
280 printf >&2 ":-----------------------------------------------------------------------------\n"
281 printf >&2 "Running command:\n"
283 printf >&2 "%q " "${@}"
291 printf >>netdata-installer.log "FAILED!\n"
293 printf >>netdata-installer.log "OK\n"
299 if [ ${ZLIB_IS_HERE} -eq 1 ]
302 echo >&2 "ok, assuming zlib is really installed."
303 export ZLIB_CFLAGS=" "
304 export ZLIB_LIBS="-lz"
307 trap build_error EXIT
309 if [ "$have_autotools" ]
311 run ./autogen.sh || exit 1
315 --prefix="${NETDATA_PREFIX}/usr" \
316 --sysconfdir="${NETDATA_PREFIX}/etc" \
317 --localstatedir="${NETDATA_PREFIX}/var" \
318 --with-zlib --with-math --with-user=netdata \
319 CFLAGS="${CFLAGS}" || exit 1
321 # remove the build_error hook
324 if [ -f src/netdata ]
326 echo >&2 "Cleaning a possibly old compilation ..."
330 echo >&2 "Compiling netdata ..."
333 # backup user configurations
334 for x in apps_groups.conf charts.d.conf
336 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}" ]
338 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}" "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup"
342 echo >&2 "Installing netdata ..."
343 run make install || exit 1
345 # restore user configurations
346 for x in apps_groups.conf charts.d.conf
348 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" ]
350 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" "${NETDATA_PREFIX}/etc/netdata/${x}"
354 NETDATA_ADDED_TO_DOCKER=0
357 getent group netdata > /dev/null
360 echo >&2 "Adding netdata user group ..."
361 run groupadd -r netdata
364 getent passwd netdata > /dev/null
367 echo >&2 "Adding netdata user account ..."
368 run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
371 getent group docker > /dev/null
374 # find the users in the docker group
375 docker=$(getent group docker | cut -d ':' -f 4)
376 if [[ ",${docker}," =~ ,netdata, ]]
378 # netdata is already there
381 # netdata is not in docker group
382 echo >&2 "Adding netdata user to the docker group (needed to get container names) ..."
383 run usermod -a -G docker netdata
385 # let the uninstall script know
386 NETDATA_ADDED_TO_DOCKER=1
391 # -----------------------------------------------------------------------------
392 # load options from the configuration file
394 # create an empty config if it does not exist
395 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
397 # function to extract values from the config file
399 local key="${1}" value="${2}" line=
401 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
403 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
404 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
412 [ ! "${UID}" = "0" ] && defuser="${USER}"
413 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
415 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
416 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
420 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
424 NETDATA_PORT="$( config_option "port" ${defport} )"
427 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
428 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
429 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
430 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
431 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
432 NETDATA_BIND="$( config_option "bind socket to IP" "*" )"
433 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
436 # -----------------------------------------------------------------------------
437 # prepare the directories
439 # this is needed if NETDATA_PREFIX is not empty
440 if [ ! -d "${NETDATA_RUN_DIR}" ]
442 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
445 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
446 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}" "${NETDATA_LIB_DIR}"
450 echo >&2 "Creating directory '${x}'"
451 run mkdir -p "${x}" || exit 1
456 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
458 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}..."
460 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
464 run chmod 0755 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
469 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
470 run chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
471 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
474 # fix apps.plugin to be setuid to root
475 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
476 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
480 # -----------------------------------------------------------------------------
481 # check if we can re-start netdata
483 if [ ${DONOTSTART} -eq 1 ]
485 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
487 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
488 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
490 if [ "${UID}" -eq 0 ]
492 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
494 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
496 echo >&2 "OK. It is now installed and ready."
500 # -----------------------------------------------------------------------------
501 # stop a running netdata
504 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
505 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
511 echo >&2 "-------------------------------------------------------------------------------"
513 printf >&2 "Stopping a (possibly) running netdata..."
520 echo >&2 "Cannot stop the running netdata."
526 pid=$(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null)
527 # backwards compatibility
528 [ -z "${pid}" ] && pid=$(cat /var/run/netdata.pid 2>/dev/null)
529 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
531 isnetdata $pid || pid=
534 run kill $pid 2>/dev/null
537 run killall netdata 2>/dev/null
541 test $ret -eq 0 && printf >&2 "." && sleep 2
547 # -----------------------------------------------------------------------------
550 echo >&2 "Starting netdata..."
551 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile ${NETDATA_RUN_DIR}/netdata.pid "${@}"
556 echo >&2 "SORRY! FAILED TO START NETDATA!"
559 echo >&2 "OK. NetData Started!"
564 # -----------------------------------------------------------------------------
565 # save a config file, if it is not already there
567 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
570 echo >&2 "-------------------------------------------------------------------------------"
572 echo >&2 "Downloading default configuration from netdata..."
575 # remove a possibly obsolete download
576 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
578 # disable a proxy to get data from the local netdata
583 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
587 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
589 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
593 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
595 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
596 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
598 if [ "${UID}" -eq 0 ]
600 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
602 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
604 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
605 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
609 # -----------------------------------------------------------------------------
612 ksm_is_available_but_disabled() {
615 -------------------------------------------------------------------------------
616 Memory de-duplication instructions
618 I see you have kernel memory de-duper (called Kernel Same-page Merging,
619 or KSM) available, but it is not currently enabled.
623 echo 1 >/sys/kernel/mm/ksm/run
624 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
626 If you enable it, you will save 40-60% of netdata memory.
631 ksm_is_not_available() {
634 -------------------------------------------------------------------------------
635 Memory de-duplication not present in your kernel
637 It seems you do not have kernel memory de-duper (called Kernel Same-page
638 Merging, or KSM) available.
640 To enable it, you need a kernel built with CONFIG_KSM=y
642 If you can have it, you will save 40-60% of netdata memory.
647 if [ -f "/sys/kernel/mm/ksm/run" ]
649 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
651 ksm_is_available_but_disabled
657 # -----------------------------------------------------------------------------
658 # Check for version.txt
660 if [ ! -s web/version.txt ]
664 -------------------------------------------------------------------------------
665 Version update check warning
667 The way you downloaded netdata, we cannot find its version. This means the
668 Update check on the dashboard, will not work.
670 If you want to have version update check, please re-install it
671 following the procedure in:
673 https://github.com/firehol/netdata/wiki/Installation
678 # -----------------------------------------------------------------------------
679 # apps.plugin warning
681 if [ "${UID}" -ne 0 ]
683 cat <<-SETUID_WARNING
685 -------------------------------------------------------------------------------
686 apps.plugin needs privileges
688 Since you have installed netdata as a normal user, to have apps.plugin collect
689 all the needed data, you have to give it the access rights it needs, by running
690 either of the following sets of commands:
692 To run apps.plugin with escalated capabilities:
694 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
695 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
696 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
698 or, to run apps.plugin as root:
700 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
701 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
703 These commands allow apps.plugin to run as root.
705 apps.plugin is performing a hard-coded function of data collection for all
706 running processes. It cannot be instructed from the netdata daemon to perform
707 any task, so it is pretty safe to do this.
712 # -----------------------------------------------------------------------------
713 # Keep un-install info
715 cat >netdata-uninstaller.sh <<-UNINSTALL
718 # this script will uninstall netdata
720 if [ "\$1" != "--force" ]
722 echo >&2 "This script will REMOVE netdata from your system."
723 echo >&2 "Run it again with --force to do it."
727 echo >&2 "Stopping a possibly running netdata..."
732 if [ ! -z "\$1" -a -d "\$1" ]
735 echo "Deleting directory '\$1' ..."
740 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
742 # installation prefix was given
744 deletedir "${NETDATA_PREFIX}"
747 # installation prefix was NOT given
749 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
751 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
752 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
755 deletedir "${NETDATA_PREFIX}/etc/netdata"
756 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
757 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
758 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
759 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
760 deletedir "${NETDATA_PREFIX}/var/log/netdata"
763 getent passwd netdata > /dev/null
767 echo "You may also want to remove the user netdata"
769 echo " userdel netdata"
772 getent group netdata > /dev/null
776 echo "You may also want to remove the group netdata"
778 echo " groupdel netdata"
781 getent group docker > /dev/null
782 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
785 echo "You may also want to remove the netdata user from the docker group"
787 echo " gpasswd -d netdata docker"
791 chmod 750 netdata-uninstaller.sh
793 # -----------------------------------------------------------------------------
795 if [ "${NETDATA_BIND}" = "*" ]
799 access="${NETDATA_BIND}"
805 -------------------------------------------------------------------------------
807 OK. NetData is installed and it is running (listening to ${NETDATA_BIND}:${NETDATA_PORT}).
809 -------------------------------------------------------------------------------
812 Hit http://${access}:${NETDATA_PORT}/ from your browser.
814 To stop netdata, just kill it, with:
818 To start it, just run it:
820 ${NETDATA_PREFIX}/usr/sbin/netdata
826 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"