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}
15 # you can set CFLAGS before running installer
16 CFLAGS="${CFLAGS--O3}"
18 # keep a log of this command
19 printf "\n# " >>netdata-installer.log
20 date >>netdata-installer.log
21 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
22 printf "%q " "$0" "${@}" >>netdata-installer.log
23 printf "\n" >>netdata-installer.log
34 ${ME} <installer options>
36 Valid <installer options> are:
38 --install /PATH/TO/INSTALL
40 If your give: --install /opt
41 netdata will be installed in /opt/netdata
45 Do not (re)start netdata.
50 Do not wait for the user to press ENTER.
51 Start immediately building it.
55 If you get errors about missing zlib,
56 but you know it is available,
57 you have a broken pkg-config.
58 Use this option to allow it continue
59 without checking pkg-config.
61 Netdata will by default be compiled with gcc optimization -O3
62 If you need to pass different CFLAGS, use something like this:
64 CFLAGS="<gcc options>" $ME <installer options>
66 For the installer to complete successfully, you will need
67 these packages installed:
69 gcc make autoconf automake pkg-config zlib1g-dev uuid-dev
71 For the plugins, you will at least need:
80 if [ "$1" = "--install" ]
82 NETDATA_PREFIX="${2}/netdata"
84 elif [ "$1" = "--zlib-is-really-here" ]
88 elif [ "$1" = "--dont-start-it" ]
92 elif [ "$1" = "--dont-wait" ]
96 elif [ "$1" = "--help" -o "$1" = "-h" ]
103 echo >&2 "I cannot understand option '$1'."
112 Nice to see you are giving it a try!
114 You are about to build and install netdata to your system.
116 It will be installed at these locations:
118 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
119 - config files at ${NETDATA_PREFIX}/etc/netdata
120 - web files at ${NETDATA_PREFIX}/usr/share/netdata
121 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
122 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
123 - db files at ${NETDATA_PREFIX}/var/lib/netdata
124 - log files at ${NETDATA_PREFIX}/var/log/netdata
125 - pid file at ${NETDATA_PREFIX}/var/run
127 This installer allows you to change the installation path.
128 Press Control-C and run the same command with --help for help.
132 if [ "${UID}" -ne 0 ]
134 if [ -z "${NETDATA_PREFIX}" ]
136 cat <<NONROOTNOPREFIX
138 Sorry! This will fail!
140 You are attempting to install netdata as non-root, but you plan to install it
143 Please set an installation prefix, like this:
145 $0 ${@} --install /tmp
147 or, run the installer as root:
151 We suggest to install it as root, or certain data collectors will not be able
152 to work. Netdata drops root privileges when running. So, if you plan to keep
153 it, install it as root to get the full functionality.
162 You are about to install netdata as a non-root user.
163 Netdata will work, but a few data collection modules that
164 require root access will fail.
166 If you installing permanently on your system, run the
176 if [ "$(type autoreconf 2> /dev/null)" ]
184 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
185 eval $maj=\$1 $min=\$2
187 autoconf_maj_min AMAJ AMIN
192 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
196 echo "Found autotools $AMAJ.$AMIN"
199 echo "No autotools found"
202 if [ ! "$have_autotools" ]
206 echo "Will skip autoreconf step"
210 -------------------------------------------------------------------------------
211 autotools 2.60 or later is required
213 Sorry, you do not seem to have autotools 2.60 or later, which is
214 required to build from the git sources of netdata.
216 You can either install a suitable version of autotools and automake
217 or download a netdata package which does not have these dependencies.
219 Source packages where autotools have already been run are available
221 https://firehol.org/download/netdata/
223 The unsigned/master folder tracks the head of the git tree and released
224 packages are also available.
230 if [ ${DONOTWAIT} -eq 0 ]
232 if [ ! -z "${NETDATA_PREFIX}" ]
234 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
236 read -p "Press ENTER to build and install netdata to your system > "
243 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245 Sorry! NetData failed to build...
247 You many need to check these:
249 1. The package zlib1g-dev has to be installed.
251 If your system cannot find ZLIB, although it is installed
252 run me with the option: --zlib-is-really-here
254 2. The package uuid-dev has to be installed.
256 3. You need basic build tools installed, like:
258 gcc make autoconf automake pkg-config
260 Autoconf version 2.60 or higher is required.
262 If you still cannot get it to build, ask for help at github:
264 https://github.com/firehol/netdata/issues
274 printf >&2 ":-----------------------------------------------------------------------------\n"
275 printf >&2 "Running command:\n"
277 printf >&2 "%q " "${@}"
284 if [ ${ZLIB_IS_HERE} -eq 1 ]
287 echo >&2 "ok, assuming zlib is really installed."
288 export ZLIB_CFLAGS=" "
289 export ZLIB_LIBS="-lz"
292 trap build_error EXIT
294 if [ "$have_autotools" ]
296 run ./autogen.sh || exit 1
300 --prefix="${NETDATA_PREFIX}/usr" \
301 --sysconfdir="${NETDATA_PREFIX}/etc" \
302 --localstatedir="${NETDATA_PREFIX}/var" \
303 --with-zlib --with-math --with-user=netdata \
304 CFLAGS="${CFLAGS}" || exit 1
306 # remove the build_error hook
309 if [ -f src/netdata ]
311 echo >&2 "Cleaning a possibly old compilation ..."
315 echo >&2 "Compiling netdata ..."
318 # backup user configurations
319 for x in apps_groups.conf charts.d.conf
321 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}" ]
323 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}" "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup"
327 echo >&2 "Installing netdata ..."
328 run make install || exit 1
330 # restore user configurations
331 for x in apps_groups.conf charts.d.conf
333 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" ]
335 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" "${NETDATA_PREFIX}/etc/netdata/${x}"
339 NETDATA_ADDED_TO_DOCKER=0
342 getent group netdata > /dev/null
345 echo >&2 "Adding netdata user group ..."
346 run groupadd -r netdata
349 getent passwd netdata > /dev/null
352 echo >&2 "Adding netdata user account ..."
353 run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
356 getent group docker > /dev/null
359 # find the users in the docker group
360 docker=$(getent group docker | cut -d ':' -f 4)
361 if [[ ",${docker}," =~ ,netdata, ]]
363 # netdata is already there
366 # netdata is not in docker group
367 echo >&2 "Adding netdata user to the docker group (needed to get container names) ..."
368 run usermod -a -G docker netdata
370 # let the uninstall script know
371 NETDATA_ADDED_TO_DOCKER=1
376 # -----------------------------------------------------------------------------
377 # load options from the configuration file
379 # create an empty config if it does not exist
380 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
382 # function to extract values from the config file
384 local key="${1}" value="${2}" line=
386 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
388 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
389 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
397 [ ! "${UID}" = "0" ] && defuser="${USER}"
398 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
400 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
401 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
405 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
409 NETDATA_PORT="$( config_option "port" ${defport} )"
412 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
413 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
414 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
415 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
416 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
417 NETDATA_BIND="$( config_option "bind socket to IP" "*" )"
418 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
421 # -----------------------------------------------------------------------------
422 # prepare the directories
424 # this is needed if NETDATA_PREFIX is not empty
425 if [ ! -d "${NETDATA_RUN_DIR}" ]
427 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
430 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
431 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}" "${NETDATA_LIB_DIR}"
435 echo >&2 "Creating directory '${x}'"
436 run mkdir -p "${x}" || exit 1
441 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
443 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}..."
445 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
449 run chmod 0755 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
454 # fix apps.plugin to be setuid to root
455 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
456 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
459 # -----------------------------------------------------------------------------
460 # check if we can re-start netdata
462 if [ ${DONOTSTART} -eq 1 ]
464 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
466 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
467 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
469 if [ "${UID}" -eq 0 ]
471 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
473 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
475 echo >&2 "OK. It is now installed and ready."
479 # -----------------------------------------------------------------------------
480 # stop a running netdata
483 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
484 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
489 printf >&2 "Stopping a (possibly) running netdata..."
496 echo >&2 "Cannot stop the running netdata."
502 pid=$(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null)
503 # backwards compatibility
504 [ -z "${pid}" ] && pid=$(cat /var/run/netdata.pid 2>/dev/null)
505 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
507 isnetdata $pid || pid=
510 run kill $pid 2>/dev/null
513 run killall netdata 2>/dev/null
517 test $ret -eq 0 && printf >&2 "." && sleep 2
523 # -----------------------------------------------------------------------------
526 echo >&2 "Starting netdata..."
527 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile ${NETDATA_RUN_DIR}/netdata.pid "${@}"
532 echo >&2 "SORRY! FAILED TO START NETDATA!"
535 echo >&2 "OK. NetData Started!"
539 # -----------------------------------------------------------------------------
540 # save a config file, if it is not already there
542 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
544 echo >&2 "Downloading default configuration from netdata..."
547 # remove a possibly obsolete download
548 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
550 # disable a proxy to get data from the local netdata
555 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
559 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
561 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
565 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
567 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
568 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
570 if [ "${UID}" -eq 0 ]
572 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
574 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
576 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
577 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
581 # -----------------------------------------------------------------------------
584 ksm_is_available_but_disabled() {
587 -------------------------------------------------------------------------------
588 Memory de-duplication instructions
590 I see you have kernel memory de-duper (called Kernel Same-page Merging,
591 or KSM) available, but it is not currently enabled.
595 echo 1 >/sys/kernel/mm/ksm/run
596 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
598 If you enable it, you will save 40-60% of netdata memory.
603 ksm_is_not_available() {
606 -------------------------------------------------------------------------------
607 Memory de-duplication not present in your kernel
609 It seems you do not have kernel memory de-duper (called Kernel Same-page
610 Merging, or KSM) available.
612 To enable it, you need a kernel built with CONFIG_KSM=y
614 If you can have it, you will save 40-60% of netdata memory.
619 if [ -f "/sys/kernel/mm/ksm/run" ]
621 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
623 ksm_is_available_but_disabled
629 # -----------------------------------------------------------------------------
630 # Check for version.txt
632 if [ ! -s web/version.txt ]
636 -------------------------------------------------------------------------------
637 Version update check warning
639 The way you downloaded netdata, we cannot find its version. This means the
640 Update check on the dashboard, will not work.
642 If you want to have version update check, please re-install it
643 following the procedure in:
645 https://github.com/firehol/netdata/wiki/Installation
650 # -----------------------------------------------------------------------------
651 # apps.plugin warning
653 if [ "${UID}" -ne 0 ]
657 -------------------------------------------------------------------------------
658 apps.plugin needs privileges
660 Since you have installed netdata as a normal user, to have apps.plugin collect
661 all the needed data, you have to give it the access rights it needs, by running
664 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
665 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
667 The commands allow apps.plugin to run as root.
669 apps.plugin is performing a hard-coded function of data collection for all
670 running processes. It cannot be instructed from the netdata daemon to perform
671 any task, so it is pretty safe to do this.
676 # -----------------------------------------------------------------------------
677 # Keep un-install info
679 cat >netdata-uninstaller.sh <<UNINSTALL
682 # this script will uninstall netdata
684 if [ "\$1" != "--force" ]
686 echo >&2 "This script will REMOVE netdata from your system."
687 echo >&2 "Run it again with --force to do it."
691 echo >&2 "Stopping a possibly running netdata..."
696 if [ ! -z "\$1" -a -d "\$1" ]
699 echo "Deleting directory '\$1' ..."
704 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
706 # installation prefix was given
708 deletedir "${NETDATA_PREFIX}"
711 # installation prefix was NOT given
713 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
715 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
716 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
719 deletedir "${NETDATA_PREFIX}/etc/netdata"
720 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
721 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
722 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
723 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
724 deletedir "${NETDATA_PREFIX}/var/log/netdata"
727 getent passwd netdata > /dev/null
731 echo "You may also want to remove the user netdata"
733 echo " userdel netdata"
736 getent group netdata > /dev/null
740 echo "You may also want to remove the group netdata"
742 echo " groupdel netdata"
745 getent group docker > /dev/null
746 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
749 echo "You may also want to remove the netdata user from the docker group"
751 echo " gpasswd -d netdata docker"
755 chmod 750 netdata-uninstaller.sh
757 # -----------------------------------------------------------------------------
759 if [ "${NETDATA_BIND}" = "*" ]
763 access="${NETDATA_BIND}"
769 -------------------------------------------------------------------------------
771 OK. NetData is installed and it is running (listening to ${NETDATA_BIND}:${NETDATA_PORT}).
773 -------------------------------------------------------------------------------
776 Hit http://${access}:${NETDATA_PORT}/ from your browser.
778 To stop netdata, just kill it, with:
782 To start it, just run it:
784 ${NETDATA_PREFIX}/usr/sbin/netdata
789 Give netdata a Github Star, at:
791 https://github.com/firehol/netdata/wiki
795 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"