3 # reload the user profile
4 [ -f /etc/profile ] && . /etc/profile
8 # you can set CFLAGS before running installer
11 # keep a log of this command
12 printf "\n# " >>netdata-installer.log
13 date >>netdata-installer.log
14 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
15 printf "%q " "$0" "${@}" >>netdata-installer.log
16 printf "\n" >>netdata-installer.log
27 ${ME} <installer options>
29 Valid <installer options> are:
31 --install /PATH/TO/INSTALL
33 If your give: --install /opt
34 netdata will be installed in /opt/netdata
38 Do not (re)start netdata.
43 Do not wait for the user to press ENTER.
44 Start immediately building it.
48 If you get errors about missing zlib,
49 but you know it is available,
50 you have a broken pkg-config.
51 Use this option to allow it continue
52 without checking pkg-config.
54 Netdata will by default be compiled with gcc optimization -O3
55 If you need to pass different CFLAGS, use something like this:
57 CFLAGS="<gcc options>" $ME <installer options>
59 For the installer to complete successfully, you will need
60 these packages installed:
62 gcc make autoconf automake pkg-config zlib1g-dev
64 For the plugins, you will at least need:
73 if [ "$1" = "--install" ]
75 NETDATA_PREFIX="${2}/netdata"
77 elif [ "$1" = "--zlib-is-really-here" ]
81 elif [ "$1" = "--dont-start-it" ]
85 elif [ "$1" = "--dont-wait" ]
89 elif [ "$1" = "--help" -o "$1" = "-h" ]
96 echo >&2 "I cannot understand option '$1'."
105 Nice to see you are giving it a try!
107 You are about to build and install netdata to your system.
109 It will be installed at these locations:
111 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
112 - config files at ${NETDATA_PREFIX}/etc/netdata
113 - web files at ${NETDATA_PREFIX}/usr/share/netdata
114 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
115 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
116 - log files at ${NETDATA_PREFIX}/var/log/netdata
117 - pid file at ${NETDATA_PREFIX}/var/run
119 This installer allows you to change the installation path.
120 Press Control-C and run the same command with --help for help.
124 if [ "${UID}" -ne 0 ]
126 if [ -z "${NETDATA_PREFIX}" ]
128 cat <<NONROOTNOPREFIX
130 Sorry! This will wrong!
132 You are attempting to install netdata as non-root, but you plan to install it
135 Please set an installation prefix, like this:
137 $0 ${@} --install /tmp
139 or, run the installer as root:
143 We suggest to install it as root, or certain data collectors will not be able
144 to work. Netdata drops root privileges when running. So, if you plan to keep
145 it, install it as root to get the full functionality.
154 You are about to install netdata as a non-root user.
155 Netdata will work, but a few data collection modules that
156 require root access will fail.
158 If you installing permanently on your system, run the
168 if [ "$(type autoreconf 2> /dev/null)" ]
176 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
177 eval $maj=\$1 $min=\$2
179 autoconf_maj_min AMAJ AMIN
184 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
188 echo "Found autotools $AMAJ.$AMIN"
191 echo "No autotools found"
194 if [ ! "$have_autotools" ]
198 echo "Will skip autoreconf step"
202 -------------------------------------------------------------------------------
203 autotools 2.60 or later is required
205 Sorry, you do not seem to have autotools 2.60 or later, which is
206 required to build from the git sources of netdata.
208 You can either install a suitable version of autotools and automake
209 or download a netdata package which does not have these dependencies.
211 Source packages where autotools have already been run are available
213 https://firehol.org/download/netdata/
215 The unsigned/master folder tracks the head of the git tree and released
216 packages are also available.
222 if [ ${DONOTWAIT} -eq 0 ]
224 if [ ! -z "${NETDATA_PREFIX}" ]
226 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
228 read -p "Press ENTER to build and install netdata to your system > "
235 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237 Sorry! NetData failed to build...
239 You many need to check these:
241 1. The package zlib1g-dev has to be installed.
243 2. You need basic build tools installed, like:
245 gcc make autoconf automake pkg-config
247 Autoconf version 2.60 or higher is required
249 3. If your system cannot find ZLIB, although it is installed
250 run me with the option: --zlib-is-really-here
253 If you still cannot get it to build, ask for help at github:
255 https://github.com/firehol/netdata/issues
265 printf >&2 ":-----------------------------------------------------------------------------\n"
266 printf >&2 "Running command:\n"
268 printf >&2 "%q " "${@}"
275 if [ ${ZLIB_IS_HERE} -eq 1 ]
278 echo >&2 "ok, assuming zlib is really installed."
279 export ZLIB_CFLAGS=" "
280 export ZLIB_LIBS="-lz"
283 trap build_error EXIT
285 if [ "$have_autotools" ]
287 run ./autogen.sh || exit 1
291 --prefix="${NETDATA_PREFIX}/usr" \
292 --sysconfdir="${NETDATA_PREFIX}/etc" \
293 --localstatedir="${NETDATA_PREFIX}/var" \
294 --with-zlib --with-math --with-user=netdata \
295 CFLAGS="${CFLAGS}" || exit 1
297 # remove the build_error hook
300 if [ -f src/netdata ]
302 echo >&2 "Cleaning a possibly old compilation ..."
306 echo >&2 "Compiling netdata ..."
309 # backup user configurations
310 for x in apps_groups.conf charts.d.conf
312 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}" ]
314 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}" "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup"
318 echo >&2 "Installing netdata ..."
319 run make install || exit 1
321 # restore user configurations
322 for x in apps_groups.conf charts.d.conf
324 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" ]
326 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" "${NETDATA_PREFIX}/etc/netdata/${x}"
332 echo >&2 "Adding netdata user group ..."
333 getent group netdata > /dev/null || run groupadd -r netdata
335 echo >&2 "Adding netdata user account ..."
336 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
340 # -----------------------------------------------------------------------------
341 # load options from the configuration file
343 # create an empty config if it does not exist
344 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
346 # function to extract values from the config file
348 local key="${1}" value="${2}" line=
350 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
352 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
353 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
361 [ ! "${UID}" = "0" ] && defuser="${USER}"
362 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
364 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
365 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
369 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
373 NETDATA_PORT="$( config_option "port" ${defport} )"
376 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
377 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
378 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
379 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
380 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
383 # -----------------------------------------------------------------------------
384 # prepare the directories
386 # this is needed if NETDATA_PREFIX is not empty
387 if [ ! -d "${NETDATA_RUN_DIR}" ]
389 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
392 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
393 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
397 echo >&2 "Creating directory '${x}'"
398 run mkdir -p "${x}" || exit 1
403 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
405 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}..."
407 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
411 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
416 # fix apps.plugin to be setuid to root
417 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
418 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
421 # -----------------------------------------------------------------------------
422 # check if we can re-start netdata
424 if [ ${DONOTSTART} -eq 1 ]
426 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
428 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
429 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
431 if [ "${UID}" -eq 0 ]
433 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
435 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
437 echo >&2 "OK. It is now installed and ready."
441 # -----------------------------------------------------------------------------
442 # stop a running netdata
445 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
446 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
451 printf >&2 "Stopping a (possibly) running netdata..."
458 echo >&2 "Cannot stop the running netdata."
464 pid=$(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null)
465 # backwards compatibility
466 [ -z "${pid}" ] && pid=$(cat /var/run/netdata.pid 2>/dev/null)
467 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
469 isnetdata $pid || pid=
472 run kill $pid 2>/dev/null
475 run killall netdata 2>/dev/null
479 test $ret -eq 0 && printf >&2 "." && sleep 2
485 # -----------------------------------------------------------------------------
488 echo >&2 "Starting netdata..."
489 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile ${NETDATA_RUN_DIR}/netdata.pid "${@}"
494 echo >&2 "SORRY! FAILED TO START NETDATA!"
497 echo >&2 "OK. NetData Started!"
501 # -----------------------------------------------------------------------------
502 # save a config file, if it is not already there
504 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
506 echo >&2 "Downloading default configuration from netdata..."
509 # remove a possibly obsolete download
510 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
512 # disable a proxy to get data from the local netdata
517 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
521 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
523 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
527 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
529 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
530 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
532 if [ "${UID}" -eq 0 ]
534 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
536 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
538 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
539 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
543 # -----------------------------------------------------------------------------
546 ksm_is_available_but_disabled() {
549 -------------------------------------------------------------------------------
550 Memory de-duplication instructions
552 I see you have kernel memory de-duper (called Kernel Same-page Merging,
553 or KSM) available, but it is not currently enabled.
557 echo 1 >/sys/kernel/mm/ksm/run
558 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
560 If you enable it, you will save 40-60% of netdata memory.
565 ksm_is_not_available() {
568 -------------------------------------------------------------------------------
569 Memory de-duplication not present in your kernel
571 It seems you do not have kernel memory de-duper (called Kernel Same-page
572 Merging, or KSM) available.
574 To enable it, you need a kernel built with CONFIG_KSM=y
576 If you can have it, you will save 40-60% of netdata memory.
581 if [ -f "/sys/kernel/mm/ksm/run" ]
583 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
585 ksm_is_available_but_disabled
591 # -----------------------------------------------------------------------------
592 # Check for version.txt
594 if [ ! -s web/version.txt ]
598 -------------------------------------------------------------------------------
599 Version update check warning
601 The way you downloaded netdata, we cannot find its version. This means the
602 Update check on the dashboard, will not work.
604 If you want to have version update check, please re-install it
605 following the procedure in:
607 https://github.com/firehol/netdata/wiki/Installation
612 # -----------------------------------------------------------------------------
613 # apps.plugin warning
615 if [ "${UID}" -ne 0 ]
619 -------------------------------------------------------------------------------
620 apps.plugin needs privileges
622 Since you have installed netdata as a normal user, to have apps.plugin collect
623 all the needed data, you have to give it the access rights it needs, by running
626 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
627 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
629 The commands allow apps.plugin to run as root.
631 apps.plugin is performing a hard-coded function of data collection for all
632 running processes. It cannot be instructed from the netdata daemon to perform
633 any task, so it is pretty safe to do this.
638 # -----------------------------------------------------------------------------
639 # Keep un-install info
641 cat >netdata-uninstaller.sh <<UNINSTALL
644 # this script will uninstall netdata
646 if [ "\$1" != "--force" ]
648 echo >&2 "This script will REMOVE netdata from your system."
649 echo >&2 "Run it again with --force to do it."
653 echo >&2 "Stopping a possibly running netdata..."
658 if [ ! -z "\$1" -a -d "\$1" ]
661 echo "Deleting directory '\$1' ..."
666 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
668 # installation prefix was given
670 deletedir "${NETDATA_PREFIX}"
673 # installation prefix was NOT given
675 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
677 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
678 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
681 deletedir "${NETDATA_PREFIX}/etc/netdata"
682 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
683 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
684 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
685 deletedir "${NETDATA_PREFIX}/var/log/netdata"
688 getent passwd netdata > /dev/null
692 echo "You may also want to remove the user netdata"
694 echo " userdel netdata"
697 getent group netdata > /dev/null
701 echo "You may also want to remove the group netdata"
703 echo " groupdel netdata"
707 chmod 750 netdata-uninstaller.sh
709 # -----------------------------------------------------------------------------
714 -------------------------------------------------------------------------------
716 OK. NetData is installed and it is running.
718 -------------------------------------------------------------------------------
721 Hit http://localhost:${NETDATA_PORT}/ from your browser.
723 To stop netdata, just kill it, with:
727 To start it, just run it:
729 ${NETDATA_PREFIX}/usr/sbin/netdata
734 Give netdata a Github Star, at:
736 https://github.com/firehol/netdata/wiki
740 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"