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 uuid-dev
72 For the plugins, you will at least need:
81 if [ "$1" = "--install" ]
83 NETDATA_PREFIX="${2}/netdata"
85 elif [ "$1" = "--zlib-is-really-here" ]
89 elif [ "$1" = "--dont-start-it" ]
93 elif [ "$1" = "--dont-wait" ]
97 elif [ "$1" = "--help" -o "$1" = "-h" ]
104 echo >&2 "I cannot understand option '$1'."
113 Nice to see you are giving it a try!
115 You are about to build and install netdata to your system.
117 It will be installed at these locations:
119 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
120 - config files at ${NETDATA_PREFIX}/etc/netdata
121 - web files at ${NETDATA_PREFIX}/usr/share/netdata
122 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
123 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
124 - db files at ${NETDATA_PREFIX}/var/lib/netdata
125 - log files at ${NETDATA_PREFIX}/var/log/netdata
126 - pid file at ${NETDATA_PREFIX}/var/run
128 This installer allows you to change the installation path.
129 Press Control-C and run the same command with --help for help.
133 if [ "${UID}" -ne 0 ]
135 if [ -z "${NETDATA_PREFIX}" ]
137 cat <<-NONROOTNOPREFIX
139 Sorry! This will fail!
141 You are attempting to install netdata as non-root, but you plan to install it
144 Please set an installation prefix, like this:
146 $0 ${@} --install /tmp
148 or, run the installer as root:
152 We suggest to install it as root, or certain data collectors will not be able
153 to work. Netdata drops root privileges when running. So, if you plan to keep
154 it, install it as root to get the full functionality.
163 You are about to install netdata as a non-root user.
164 Netdata will work, but a few data collection modules that
165 require root access will fail.
167 If you installing permanently on your system, run the
177 if [ "$(type autoreconf 2> /dev/null)" ]
185 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
186 eval $maj=\$1 $min=\$2
188 autoconf_maj_min AMAJ AMIN
193 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
197 echo "Found autotools $AMAJ.$AMIN"
200 echo "No autotools found"
203 if [ ! "$have_autotools" ]
207 echo "Will skip autoreconf step"
211 -------------------------------------------------------------------------------
212 autotools 2.60 or later is required
214 Sorry, you do not seem to have autotools 2.60 or later, which is
215 required to build from the git sources of netdata.
217 You can either install a suitable version of autotools and automake
218 or download a netdata package which does not have these dependencies.
220 Source packages where autotools have already been run are available
222 https://firehol.org/download/netdata/
224 The unsigned/master folder tracks the head of the git tree and released
225 packages are also available.
231 if [ ${DONOTWAIT} -eq 0 ]
233 if [ ! -z "${NETDATA_PREFIX}" ]
235 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
237 read -p "Press ENTER to build and install netdata to your system > "
244 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
246 Sorry! NetData failed to build...
248 You many need to check these:
250 1. The package uuid-dev has to be installed.
252 2. The package zlib1g-dev has to be installed.
254 If your system cannot find ZLIB, although it is installed
255 run me with the option: --zlib-is-really-here
257 3. You need basic build tools installed, like:
259 gcc make autoconf automake pkg-config
261 Autoconf version 2.60 or higher is required.
263 If you still cannot get it to build, ask for help at github:
265 https://github.com/firehol/netdata/issues
274 printf >>netdata-installer.log "# "
275 printf >>netdata-installer.log "%q " "${@}"
276 printf >>netdata-installer.log " ... "
279 printf >&2 ":-----------------------------------------------------------------------------\n"
280 printf >&2 "Running command:\n"
282 printf >&2 "%q " "${@}"
290 printf >>netdata-installer.log "FAILED!\n"
292 printf >>netdata-installer.log "OK\n"
298 if [ ${ZLIB_IS_HERE} -eq 1 ]
301 echo >&2 "ok, assuming zlib is really installed."
302 export ZLIB_CFLAGS=" "
303 export ZLIB_LIBS="-lz"
306 trap build_error EXIT
308 if [ "$have_autotools" ]
310 run ./autogen.sh || exit 1
314 --prefix="${NETDATA_PREFIX}/usr" \
315 --sysconfdir="${NETDATA_PREFIX}/etc" \
316 --localstatedir="${NETDATA_PREFIX}/var" \
317 --with-zlib --with-math --with-user=netdata \
318 CFLAGS="${CFLAGS}" || exit 1
320 # remove the build_error hook
323 if [ -f src/netdata ]
325 echo >&2 "Cleaning a possibly old compilation ..."
329 echo >&2 "Compiling netdata ..."
332 # backup user configurations
333 for x in apps_groups.conf charts.d.conf
335 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}" ]
337 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}" "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup"
341 echo >&2 "Installing netdata ..."
342 run make install || exit 1
344 # restore user configurations
345 for x in apps_groups.conf charts.d.conf
347 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" ]
349 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" "${NETDATA_PREFIX}/etc/netdata/${x}"
353 NETDATA_ADDED_TO_DOCKER=0
356 getent group netdata > /dev/null
359 echo >&2 "Adding netdata user group ..."
360 run groupadd -r netdata
363 getent passwd netdata > /dev/null
366 echo >&2 "Adding netdata user account ..."
367 run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
370 getent group docker > /dev/null
373 # find the users in the docker group
374 docker=$(getent group docker | cut -d ':' -f 4)
375 if [[ ",${docker}," =~ ,netdata, ]]
377 # netdata is already there
380 # netdata is not in docker group
381 echo >&2 "Adding netdata user to the docker group (needed to get container names) ..."
382 run usermod -a -G docker netdata
384 # let the uninstall script know
385 NETDATA_ADDED_TO_DOCKER=1
390 # -----------------------------------------------------------------------------
391 # load options from the configuration file
393 # create an empty config if it does not exist
394 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
396 # function to extract values from the config file
398 local key="${1}" value="${2}" line=
400 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
402 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
403 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
411 [ ! "${UID}" = "0" ] && defuser="${USER}"
412 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
414 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
415 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
419 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
423 NETDATA_PORT="$( config_option "port" ${defport} )"
426 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
427 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
428 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
429 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
430 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
431 NETDATA_BIND="$( config_option "bind socket to IP" "*" )"
432 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
435 # -----------------------------------------------------------------------------
436 # prepare the directories
438 # this is needed if NETDATA_PREFIX is not empty
439 if [ ! -d "${NETDATA_RUN_DIR}" ]
441 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
444 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
445 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}" "${NETDATA_LIB_DIR}"
449 echo >&2 "Creating directory '${x}'"
450 run mkdir -p "${x}" || exit 1
455 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
457 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}..."
459 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
463 run chmod 0755 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
468 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
469 run chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
470 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
473 # fix apps.plugin to be setuid to root
474 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
475 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
479 # -----------------------------------------------------------------------------
480 # check if we can re-start netdata
482 if [ ${DONOTSTART} -eq 1 ]
484 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
486 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
487 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
489 if [ "${UID}" -eq 0 ]
491 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
493 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
495 echo >&2 "OK. It is now installed and ready."
499 # -----------------------------------------------------------------------------
500 # stop a running netdata
503 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
504 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
510 echo >&2 "-------------------------------------------------------------------------------"
512 printf >&2 "Stopping a (possibly) running netdata..."
519 echo >&2 "Cannot stop the running netdata."
525 pid=$(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null)
526 # backwards compatibility
527 [ -z "${pid}" ] && pid=$(cat /var/run/netdata.pid 2>/dev/null)
528 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
530 isnetdata $pid || pid=
533 run kill $pid 2>/dev/null
536 run killall netdata 2>/dev/null
540 test $ret -eq 0 && printf >&2 "." && sleep 2
546 # -----------------------------------------------------------------------------
549 echo >&2 "Starting netdata..."
550 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile ${NETDATA_RUN_DIR}/netdata.pid "${@}"
555 echo >&2 "SORRY! FAILED TO START NETDATA!"
558 echo >&2 "OK. NetData Started!"
562 # -----------------------------------------------------------------------------
563 # save a config file, if it is not already there
565 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
567 echo >&2 "Downloading default configuration from netdata..."
570 # remove a possibly obsolete download
571 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
573 # disable a proxy to get data from the local netdata
578 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
582 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
584 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
588 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
590 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
591 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
593 if [ "${UID}" -eq 0 ]
595 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
597 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
599 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
600 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
604 # -----------------------------------------------------------------------------
607 ksm_is_available_but_disabled() {
610 -------------------------------------------------------------------------------
611 Memory de-duplication instructions
613 I see you have kernel memory de-duper (called Kernel Same-page Merging,
614 or KSM) available, but it is not currently enabled.
618 echo 1 >/sys/kernel/mm/ksm/run
619 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
621 If you enable it, you will save 40-60% of netdata memory.
626 ksm_is_not_available() {
629 -------------------------------------------------------------------------------
630 Memory de-duplication not present in your kernel
632 It seems you do not have kernel memory de-duper (called Kernel Same-page
633 Merging, or KSM) available.
635 To enable it, you need a kernel built with CONFIG_KSM=y
637 If you can have it, you will save 40-60% of netdata memory.
642 if [ -f "/sys/kernel/mm/ksm/run" ]
644 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
646 ksm_is_available_but_disabled
652 # -----------------------------------------------------------------------------
653 # Check for version.txt
655 if [ ! -s web/version.txt ]
659 -------------------------------------------------------------------------------
660 Version update check warning
662 The way you downloaded netdata, we cannot find its version. This means the
663 Update check on the dashboard, will not work.
665 If you want to have version update check, please re-install it
666 following the procedure in:
668 https://github.com/firehol/netdata/wiki/Installation
673 # -----------------------------------------------------------------------------
674 # apps.plugin warning
676 if [ "${UID}" -ne 0 ]
678 cat <<-SETUID_WARNING
680 -------------------------------------------------------------------------------
681 apps.plugin needs privileges
683 Since you have installed netdata as a normal user, to have apps.plugin collect
684 all the needed data, you have to give it the access rights it needs, by running
685 either of the following sets of commands:
687 To run apps.plugin with escalated capabilities:
689 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
690 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
691 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
693 or, to run apps.plugin as root:
695 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
696 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
698 These commands allow apps.plugin to run as root.
700 apps.plugin is performing a hard-coded function of data collection for all
701 running processes. It cannot be instructed from the netdata daemon to perform
702 any task, so it is pretty safe to do this.
707 # -----------------------------------------------------------------------------
708 # Keep un-install info
710 cat >netdata-uninstaller.sh <<-UNINSTALL
713 # this script will uninstall netdata
715 if [ "\$1" != "--force" ]
717 echo >&2 "This script will REMOVE netdata from your system."
718 echo >&2 "Run it again with --force to do it."
722 echo >&2 "Stopping a possibly running netdata..."
727 if [ ! -z "\$1" -a -d "\$1" ]
730 echo "Deleting directory '\$1' ..."
735 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
737 # installation prefix was given
739 deletedir "${NETDATA_PREFIX}"
742 # installation prefix was NOT given
744 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
746 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
747 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
750 deletedir "${NETDATA_PREFIX}/etc/netdata"
751 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
752 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
753 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
754 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
755 deletedir "${NETDATA_PREFIX}/var/log/netdata"
758 getent passwd netdata > /dev/null
762 echo "You may also want to remove the user netdata"
764 echo " userdel netdata"
767 getent group netdata > /dev/null
771 echo "You may also want to remove the group netdata"
773 echo " groupdel netdata"
776 getent group docker > /dev/null
777 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
780 echo "You may also want to remove the netdata user from the docker group"
782 echo " gpasswd -d netdata docker"
786 chmod 750 netdata-uninstaller.sh
788 # -----------------------------------------------------------------------------
790 if [ "${NETDATA_BIND}" = "*" ]
794 access="${NETDATA_BIND}"
800 -------------------------------------------------------------------------------
802 OK. NetData is installed and it is running (listening to ${NETDATA_BIND}:${NETDATA_PORT}).
804 -------------------------------------------------------------------------------
807 Hit http://${access}:${NETDATA_PORT}/ from your browser.
809 To stop netdata, just kill it, with:
813 To start it, just run it:
815 ${NETDATA_PREFIX}/usr/sbin/netdata
820 Give netdata a Github Star, at:
822 https://github.com/firehol/netdata/wiki
826 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"