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
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 - log files at ${NETDATA_PREFIX}/var/log/netdata
124 - pid file at ${NETDATA_PREFIX}/var/run
126 This installer allows you to change the installation path.
127 Press Control-C and run the same command with --help for help.
131 if [ "${UID}" -ne 0 ]
133 if [ -z "${NETDATA_PREFIX}" ]
135 cat <<NONROOTNOPREFIX
137 Sorry! This will fail!
139 You are attempting to install netdata as non-root, but you plan to install it
142 Please set an installation prefix, like this:
144 $0 ${@} --install /tmp
146 or, run the installer as root:
150 We suggest to install it as root, or certain data collectors will not be able
151 to work. Netdata drops root privileges when running. So, if you plan to keep
152 it, install it as root to get the full functionality.
161 You are about to install netdata as a non-root user.
162 Netdata will work, but a few data collection modules that
163 require root access will fail.
165 If you installing permanently on your system, run the
175 if [ "$(type autoreconf 2> /dev/null)" ]
183 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
184 eval $maj=\$1 $min=\$2
186 autoconf_maj_min AMAJ AMIN
191 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
195 echo "Found autotools $AMAJ.$AMIN"
198 echo "No autotools found"
201 if [ ! "$have_autotools" ]
205 echo "Will skip autoreconf step"
209 -------------------------------------------------------------------------------
210 autotools 2.60 or later is required
212 Sorry, you do not seem to have autotools 2.60 or later, which is
213 required to build from the git sources of netdata.
215 You can either install a suitable version of autotools and automake
216 or download a netdata package which does not have these dependencies.
218 Source packages where autotools have already been run are available
220 https://firehol.org/download/netdata/
222 The unsigned/master folder tracks the head of the git tree and released
223 packages are also available.
229 if [ ${DONOTWAIT} -eq 0 ]
231 if [ ! -z "${NETDATA_PREFIX}" ]
233 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
235 read -p "Press ENTER to build and install netdata to your system > "
242 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
244 Sorry! NetData failed to build...
246 You many need to check these:
248 1. The package zlib1g-dev has to be installed.
250 2. You need basic build tools installed, like:
252 gcc make autoconf automake pkg-config
254 Autoconf version 2.60 or higher is required
256 3. If your system cannot find ZLIB, although it is installed
257 run me with the option: --zlib-is-really-here
260 If you still cannot get it to build, ask for help at github:
262 https://github.com/firehol/netdata/issues
272 printf >&2 ":-----------------------------------------------------------------------------\n"
273 printf >&2 "Running command:\n"
275 printf >&2 "%q " "${@}"
282 if [ ${ZLIB_IS_HERE} -eq 1 ]
285 echo >&2 "ok, assuming zlib is really installed."
286 export ZLIB_CFLAGS=" "
287 export ZLIB_LIBS="-lz"
290 trap build_error EXIT
292 if [ "$have_autotools" ]
294 run ./autogen.sh || exit 1
298 --prefix="${NETDATA_PREFIX}/usr" \
299 --sysconfdir="${NETDATA_PREFIX}/etc" \
300 --localstatedir="${NETDATA_PREFIX}/var" \
301 --with-zlib --with-math --with-user=netdata \
302 CFLAGS="${CFLAGS}" || exit 1
304 # remove the build_error hook
307 if [ -f src/netdata ]
309 echo >&2 "Cleaning a possibly old compilation ..."
313 echo >&2 "Compiling netdata ..."
316 # backup user configurations
317 for x in apps_groups.conf charts.d.conf
319 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}" ]
321 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}" "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup"
325 echo >&2 "Installing netdata ..."
326 run make install || exit 1
328 # restore user configurations
329 for x in apps_groups.conf charts.d.conf
331 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" ]
333 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" "${NETDATA_PREFIX}/etc/netdata/${x}"
339 echo >&2 "Adding netdata user group ..."
340 getent group netdata > /dev/null || run groupadd -r netdata
342 echo >&2 "Adding netdata user account ..."
343 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
347 # -----------------------------------------------------------------------------
348 # load options from the configuration file
350 # create an empty config if it does not exist
351 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
353 # function to extract values from the config file
355 local key="${1}" value="${2}" line=
357 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
359 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
360 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
368 [ ! "${UID}" = "0" ] && defuser="${USER}"
369 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
371 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
372 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
376 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
380 NETDATA_PORT="$( config_option "port" ${defport} )"
383 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
384 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
385 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
386 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
387 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
390 # -----------------------------------------------------------------------------
391 # prepare the directories
393 # this is needed if NETDATA_PREFIX is not empty
394 if [ ! -d "${NETDATA_RUN_DIR}" ]
396 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
399 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
400 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
404 echo >&2 "Creating directory '${x}'"
405 run mkdir -p "${x}" || exit 1
410 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
412 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}..."
414 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
418 run chmod 0755 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
423 # fix apps.plugin to be setuid to root
424 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
425 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
428 # -----------------------------------------------------------------------------
429 # check if we can re-start netdata
431 if [ ${DONOTSTART} -eq 1 ]
433 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
435 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
436 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
438 if [ "${UID}" -eq 0 ]
440 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
442 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
444 echo >&2 "OK. It is now installed and ready."
448 # -----------------------------------------------------------------------------
449 # stop a running netdata
452 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
453 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
458 printf >&2 "Stopping a (possibly) running netdata..."
465 echo >&2 "Cannot stop the running netdata."
471 pid=$(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null)
472 # backwards compatibility
473 [ -z "${pid}" ] && pid=$(cat /var/run/netdata.pid 2>/dev/null)
474 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
476 isnetdata $pid || pid=
479 run kill $pid 2>/dev/null
482 run killall netdata 2>/dev/null
486 test $ret -eq 0 && printf >&2 "." && sleep 2
492 # -----------------------------------------------------------------------------
495 echo >&2 "Starting netdata..."
496 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile ${NETDATA_RUN_DIR}/netdata.pid "${@}"
501 echo >&2 "SORRY! FAILED TO START NETDATA!"
504 echo >&2 "OK. NetData Started!"
508 # -----------------------------------------------------------------------------
509 # save a config file, if it is not already there
511 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
513 echo >&2 "Downloading default configuration from netdata..."
516 # remove a possibly obsolete download
517 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
519 # disable a proxy to get data from the local netdata
524 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
528 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
530 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
534 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
536 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
537 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
539 if [ "${UID}" -eq 0 ]
541 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
543 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
545 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
546 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
550 # -----------------------------------------------------------------------------
553 ksm_is_available_but_disabled() {
556 -------------------------------------------------------------------------------
557 Memory de-duplication instructions
559 I see you have kernel memory de-duper (called Kernel Same-page Merging,
560 or KSM) available, but it is not currently enabled.
564 echo 1 >/sys/kernel/mm/ksm/run
565 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
567 If you enable it, you will save 40-60% of netdata memory.
572 ksm_is_not_available() {
575 -------------------------------------------------------------------------------
576 Memory de-duplication not present in your kernel
578 It seems you do not have kernel memory de-duper (called Kernel Same-page
579 Merging, or KSM) available.
581 To enable it, you need a kernel built with CONFIG_KSM=y
583 If you can have it, you will save 40-60% of netdata memory.
588 if [ -f "/sys/kernel/mm/ksm/run" ]
590 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
592 ksm_is_available_but_disabled
598 # -----------------------------------------------------------------------------
599 # Check for version.txt
601 if [ ! -s web/version.txt ]
605 -------------------------------------------------------------------------------
606 Version update check warning
608 The way you downloaded netdata, we cannot find its version. This means the
609 Update check on the dashboard, will not work.
611 If you want to have version update check, please re-install it
612 following the procedure in:
614 https://github.com/firehol/netdata/wiki/Installation
619 # -----------------------------------------------------------------------------
620 # apps.plugin warning
622 if [ "${UID}" -ne 0 ]
626 -------------------------------------------------------------------------------
627 apps.plugin needs privileges
629 Since you have installed netdata as a normal user, to have apps.plugin collect
630 all the needed data, you have to give it the access rights it needs, by running
633 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
634 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
636 The commands allow apps.plugin to run as root.
638 apps.plugin is performing a hard-coded function of data collection for all
639 running processes. It cannot be instructed from the netdata daemon to perform
640 any task, so it is pretty safe to do this.
645 # -----------------------------------------------------------------------------
646 # Keep un-install info
648 cat >netdata-uninstaller.sh <<UNINSTALL
651 # this script will uninstall netdata
653 if [ "\$1" != "--force" ]
655 echo >&2 "This script will REMOVE netdata from your system."
656 echo >&2 "Run it again with --force to do it."
660 echo >&2 "Stopping a possibly running netdata..."
665 if [ ! -z "\$1" -a -d "\$1" ]
668 echo "Deleting directory '\$1' ..."
673 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
675 # installation prefix was given
677 deletedir "${NETDATA_PREFIX}"
680 # installation prefix was NOT given
682 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
684 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
685 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
688 deletedir "${NETDATA_PREFIX}/etc/netdata"
689 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
690 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
691 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
692 deletedir "${NETDATA_PREFIX}/var/log/netdata"
695 getent passwd netdata > /dev/null
699 echo "You may also want to remove the user netdata"
701 echo " userdel netdata"
704 getent group netdata > /dev/null
708 echo "You may also want to remove the group netdata"
710 echo " groupdel netdata"
714 chmod 750 netdata-uninstaller.sh
716 # -----------------------------------------------------------------------------
721 -------------------------------------------------------------------------------
723 OK. NetData is installed and it is running.
725 -------------------------------------------------------------------------------
728 Hit http://localhost:${NETDATA_PORT}/ from your browser.
730 To stop netdata, just kill it, with:
734 To start it, just run it:
736 ${NETDATA_PREFIX}/usr/sbin/netdata
741 Give netdata a Github Star, at:
743 https://github.com/firehol/netdata/wiki
747 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"