5 # you can set CFLAGS before running installer
8 # keep a log of this command
9 printf "\n# " >>netdata-installer.log
10 date >>netdata-installer.log
11 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
12 printf "%q " "$0" "${@}" >>netdata-installer.log
13 printf "\n" >>netdata-installer.log
24 ${ME} <installer options>
26 Valid <installer options> are:
28 --install /PATH/TO/INSTALL
30 If your give: --install /opt
31 netdata will be installed in /opt/netdata
35 Do not (re)start netdata.
40 Do not wait for the user to press ENTER.
41 Start immediately building it.
45 If you get errors about missing zlib,
46 but you know it is available,
47 you have a broken pkg-config.
48 Use this option to allow it continue
49 without checking pkg-config.
51 Netdata will by default be compiled with gcc optimization -O3
52 If you need to pass different CFLAGS, use something like this:
54 CFLAGS="<gcc options>" $ME <installer options>
56 For the installer to complete successfully, you will need
57 these packages installed:
59 gcc make autoconf automake pkg-config zlib1g-dev
61 For the plugins, you will at least need:
70 if [ "$1" = "--install" ]
72 NETDATA_PREFIX="${2}/netdata"
74 elif [ "$1" = "--zlib-is-really-here" ]
78 elif [ "$1" = "--dont-start-it" ]
82 elif [ "$1" = "--dont-wait" ]
86 elif [ "$1" = "--help" -o "$1" = "-h" ]
93 echo >&2 "I cannot understand option '$1'."
102 Nice to see you are giving it a try!
104 You are about to build and install netdata to your system.
106 It will be installed at these locations:
108 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
109 - config files at ${NETDATA_PREFIX}/etc/netdata
110 - web files at ${NETDATA_PREFIX}/usr/share/netdata
111 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
112 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
113 - log files at ${NETDATA_PREFIX}/var/log/netdata
114 - pid file at ${NETDATA_PREFIX}/var/run
116 This installer allows you to change the installation path.
117 Press Control-C and run the same command with --help for help.
121 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
124 echo >&2 "You have to run netdata as root."
125 echo >&2 "The netdata daemon will drop priviliges"
126 echo >&2 "but you have to start it as root."
132 if [ "$(type autoreconf 2> /dev/null)" ]
140 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
141 eval $maj=\$1 $min=\$2
143 autoconf_maj_min AMAJ AMIN
148 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
152 echo "Found autotools $AMAJ.$AMIN"
155 echo "No autotools found"
158 if [ ! "$have_autotools" ]
162 echo "Will skip autoreconf step"
166 Sorry, you do not seem to have autotools 2.60 or later, which is
167 required to build from the git sources of netdata.
169 You can either install a suitable version of autotools and automake
170 or download a netdata package which does not have these dependencies.
172 Source packages where autotools have already been run are available
174 https://firehol.org/download/netdata/
176 The unsigned/master folder tracks the head of the git tree and released
177 packages are also available.
183 if [ ${DONOTWAIT} -eq 0 ]
185 if [ ! -z "${NETDATA_PREFIX}" ]
187 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
189 read -p "Press ENTER to build and install netdata to your system > "
194 [ -f /etc/profile ] && . /etc/profile
199 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201 Sorry! NetData failed to build...
203 You many need to check these:
205 1. The package zlib1g-dev has to be installed.
207 2. You need basic build tools installed, like:
209 gcc make autoconf automake pkg-config
211 Autoconf version 2.60 or higher is required
213 3. If your system cannot find ZLIB, although it is installed
214 run me with the option: --zlib-is-really-here
216 If you still cannot get it to build, ask for help at github:
218 https://github.com/firehol/netdata/issues
227 printf >&2 ":-----------------------------------------------------------------------------\n"
228 printf >&2 "Running command:\n"
230 printf >&2 "%q " "${@}"
237 if [ ${ZLIB_IS_HERE} -eq 1 ]
240 echo >&2 "ok, assuming zlib is really installed."
241 export ZLIB_CFLAGS=" "
242 export ZLIB_LIBS="-lz"
245 trap build_error EXIT
247 if [ "$have_autotools" ]
249 echo >&2 "Running ./autogen.sh ..."
250 run ./autogen.sh || exit 1
253 echo >&2 "Running ./configure ..."
255 --prefix="${NETDATA_PREFIX}/usr" \
256 --sysconfdir="${NETDATA_PREFIX}/etc" \
257 --localstatedir="${NETDATA_PREFIX}/var" \
258 --with-zlib --with-math --with-user=netdata \
259 CFLAGS="${CFLAGS}" || exit 1
261 # remove the build_error hook
264 if [ -f src/netdata ]
266 echo >&2 "Cleaning a possibly old compilation ..."
270 echo >&2 "Compiling netdata ..."
273 echo >&2 "Installing netdata ..."
274 run make install || exit 1
276 echo >&2 "Adding netdata user group ..."
277 getent group netdata > /dev/null || run groupadd -r netdata
279 echo >&2 "Adding netdata user account ..."
280 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
284 # -----------------------------------------------------------------------------
285 # load options from the configuration file
287 # create an empty config if it does not exist
288 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
290 # function to extract values from the config file
292 local key="${1}" value="${2}" line=
294 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
296 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
297 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
305 [ ! "${UID}" = "0" ] && defuser="${USER}"
306 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
310 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
314 NETDATA_PORT="$( config_option "port" ${defport} )"
317 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
318 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
319 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
320 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
321 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
324 # -----------------------------------------------------------------------------
325 # prepare the directories
327 # this is needed if NETDATA_PREFIX is not empty
328 if [ ! -d "${NETDATA_RUN_DIR}" ]
330 mkdir -p "${NETDATA_RUN_DIR}" || exit 1
333 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
334 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
338 echo >&2 "Creating directory '${x}'"
339 run mkdir -p "${x}" || exit 1
341 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
342 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
345 # fix apps.plugin to be setuid to root
346 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
347 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
350 # -----------------------------------------------------------------------------
351 # check if we can re-start netdata
353 if [ ${DONOTSTART} -eq 1 ]
355 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
357 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
358 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
359 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
360 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
362 echo >&2 "OK. It is now installed and ready."
366 # -----------------------------------------------------------------------------
367 # stop a running netdata
370 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
371 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
376 printf >&2 "Stopping a (possibly) running netdata..."
383 echo >&2 "Cannot stop the running netdata."
389 pid=$(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null)
390 # backwards compatibility
391 [ -z "${pid}" ] && pid=$(cat /var/run/netdata.pid 2>/dev/null)
392 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
394 isnetdata $pid || pid=
397 run kill $pid 2>/dev/null
400 run killall netdata 2>/dev/null
404 test $ret -eq 0 && printf >&2 "." && sleep 2
410 # -----------------------------------------------------------------------------
413 echo >&2 "Starting netdata..."
414 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile ${NETDATA_RUN_DIR}/netdata.pid "${@}"
419 echo >&2 "SORRY! FAILED TO START NETDATA!"
422 echo >&2 "OK. NetData Started!"
426 # -----------------------------------------------------------------------------
427 # save a config file, if it is not already there
429 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
431 echo >&2 "Downloading default configuration from netdata..."
434 # remove a possibly obsolete download
435 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
437 # disable a proxy to get data from the local netdata
442 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
446 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
448 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
452 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
454 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
455 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
457 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
458 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
460 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
461 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
465 # -----------------------------------------------------------------------------
470 -------------------------------------------------------------------------------
472 ok. NetData is installed and is running.
474 Hit http://localhost:${NETDATA_PORT}/ from your browser.
476 To stop netdata, just kill it, with:
480 To start it, just run it:
482 ${NETDATA_PREFIX}/usr/sbin/netdata
488 # -----------------------------------------------------------------------------
491 ksm_is_available_but_disabled() {
496 I see you have kernel memory de-duper (called Kernel Same-page Merging,
497 or KSM) available, but it is not currently enabled.
501 echo 1 >/sys/kernel/mm/ksm/run
502 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
504 If you enable it, you will save 20-60% of netdata memory.
509 ksm_is_not_available() {
514 I see you do not have kernel memory de-duper (called Kernel Same-page
515 Merging, or KSM) available.
517 To enable it, you need a kernel built with CONFIG_KSM=y
519 If you can have it, you will save 20-60% of netdata memory.
524 if [ -f "/sys/kernel/mm/ksm/run" ]
526 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
528 ksm_is_available_but_disabled
534 # -----------------------------------------------------------------------------
535 # Check for version.txt
537 if [ ! -s web/version.txt ]
541 VERSION UPDATE CHECK:
543 The way you downloaded netdata, we cannot find its version.
544 This means the Update check on the dashboard, will not work.
546 If you want to have version update check, please re-install it
547 following the procedure in:
549 https://github.com/firehol/netdata/wiki/Installation
555 # -----------------------------------------------------------------------------
556 # Keep un-install info
558 cat >netdata-uninstaller.sh <<UNINSTALL
561 # this script will uninstall netdata
563 if [ "\$1" != "--force" ]
565 echo >&2 "This script will REMOVE netdata from your system."
566 echo >&2 "Run it again with --force to do it."
570 echo >&2 "Stopping a possibly running netdata..."
575 if [ ! -z "\$1" -a -d "\$1" ]
578 echo "Deleting directory '\$1' ..."
583 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
585 # installation prefix was given
587 deletedir "${NETDATA_PREFIX}"
590 # installation prefix was NOT given
592 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
594 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
595 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
598 deletedir "${NETDATA_PREFIX}/etc/netdata"
599 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
600 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
601 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
602 deletedir "${NETDATA_PREFIX}/var/log/netdata"
605 getent passwd netdata > /dev/null
609 echo "You may also want to remove the user netdata"
611 echo " userdel netdata"
614 getent group netdata > /dev/null
618 echo "You may also want to remove the group netdata"
620 echo " groupdel netdata"
624 chmod 750 netdata-uninstaller.sh
626 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"