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
115 This installer allows you to change the installation path.
116 Press Control-C and run the same command with --help for help.
120 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
123 echo >&2 "You have to run netdata as root."
124 echo >&2 "The netdata daemon will drop priviliges"
125 echo >&2 "but you have to start it as root."
131 if [ "$(type autoreconf 2> /dev/null)" ]
139 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
140 eval $maj=\$1 $min=\$2
142 autoconf_maj_min AMAJ AMIN
147 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
151 echo "Found autotools $AMAJ.$AMIN"
154 echo "No autotools found"
157 if [ ! "$have_autotools" ]
161 echo "Will skip autoreconf step"
165 Sorry, you do not seem to have autotools 2.60 or later, which is
166 required to build from the git sources of netdata.
168 You can either install a suitable version of autotools and automake
169 or download a netdata package which does not have these dependencies.
171 Source packages where autotools have already been run are available
173 https://firehol.org/download/netdata/
175 The unsigned/master folder tracks the head of the git tree and released
176 packages are also available.
182 if [ ${DONOTWAIT} -eq 0 ]
184 if [ ! -z "${NETDATA_PREFIX}" ]
186 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
188 read -p "Press ENTER to build and install netdata to your system > "
193 [ -f /etc/profile ] && . /etc/profile
198 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200 Sorry! NetData failed to build...
202 You many need to check these:
204 1. The package zlib1g-dev has to be installed.
206 2. You need basic build tools installed, like:
208 gcc make autoconf automake pkg-config
210 Autoconf version 2.60 or higher is required
212 3. If your system cannot find ZLIB, although it is installed
213 run me with the option: --zlib-is-really-here
215 If you still cannot get it to build, ask for help at github:
217 https://github.com/firehol/netdata/issues
226 printf >&2 ":-----------------------------------------------------------------------------\n"
227 printf >&2 "Running command:\n"
229 printf >&2 "%q " "${@}"
236 if [ ${ZLIB_IS_HERE} -eq 1 ]
239 echo >&2 "ok, assuming zlib is really installed."
240 export ZLIB_CFLAGS=" "
241 export ZLIB_LIBS="-lz"
244 trap build_error EXIT
246 if [ "$have_autotools" ]
248 echo >&2 "Running ./autogen.sh ..."
249 run ./autogen.sh || exit 1
252 echo >&2 "Running ./configure ..."
254 --prefix="${NETDATA_PREFIX}/usr" \
255 --sysconfdir="${NETDATA_PREFIX}/etc" \
256 --localstatedir="${NETDATA_PREFIX}/var" \
257 --with-zlib --with-math --with-user=netdata \
258 CFLAGS="${CFLAGS}" || exit 1
260 # remove the build_error hook
263 if [ -f src/netdata ]
265 echo >&2 "Cleaning a possibly old compilation ..."
269 echo >&2 "Compiling netdata ..."
272 echo >&2 "Installing netdata ..."
273 run make install || exit 1
275 echo >&2 "Adding netdata user group ..."
276 getent group netdata > /dev/null || run groupadd -r netdata
278 echo >&2 "Adding netdata user account ..."
279 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
283 # -----------------------------------------------------------------------------
284 # load options from the configuration file
286 # create an empty config if it does not exist
287 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
289 # function to extract values from the config file
291 local key="${1}" value="${2}" line=
293 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
295 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
296 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
304 [ ! "${UID}" = "0" ] && defuser="${USER}"
305 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
309 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
313 NETDATA_PORT="$( config_option "port" ${defport} )"
316 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
317 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
318 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
319 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
322 # -----------------------------------------------------------------------------
323 # prepare the directories
325 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
326 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
330 echo >&2 "Creating directory '${x}'"
331 run mkdir -p "${x}" || exit 1
333 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
334 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
337 # fix apps.plugin to be setuid to root
338 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
339 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
342 # -----------------------------------------------------------------------------
343 # check if we can re-start netdata
345 if [ ${DONOTSTART} -eq 1 ]
347 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
349 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
350 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
351 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
352 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
354 echo >&2 "OK. It is now installed and ready."
358 # -----------------------------------------------------------------------------
359 # stop a running netdata
362 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
363 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
368 printf >&2 "Stopping a (possibly) running netdata..."
375 echo >&2 "Cannot stop the running netdata."
381 pid=$(cat /var/run/netdata.pid 2>/dev/null)
382 # backwards compatibility
383 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
385 isnetdata $pid || pid=
388 run kill $pid 2>/dev/null
391 run killall netdata 2>/dev/null
395 test $ret -eq 0 && printf >&2 "." && sleep 2
400 # -----------------------------------------------------------------------------
403 echo >&2 "Starting netdata..."
404 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile /var/run/netdata.pid "${@}"
409 echo >&2 "SORRY! FAILED TO START NETDATA!"
412 echo >&2 "OK. NetData Started!"
416 # -----------------------------------------------------------------------------
417 # save a config file, if it is not already there
419 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
421 echo >&2 "Downloading default configuration from netdata..."
424 # remove a possibly obsolete download
425 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
427 # disable a proxy to get data from the local netdata
432 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
436 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
438 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
442 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
444 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
445 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
447 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
448 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
450 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
451 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
455 # -----------------------------------------------------------------------------
460 -------------------------------------------------------------------------------
462 ok. NetData is installed and is running.
464 Hit http://localhost:${NETDATA_PORT}/ from your browser.
466 To stop netdata, just kill it, with:
470 To start it, just run it:
472 ${NETDATA_PREFIX}/usr/sbin/netdata
478 # -----------------------------------------------------------------------------
481 ksm_is_available_but_disabled() {
486 I see you have kernel memory de-duper (called Kernel Same-page Merging,
487 or KSM) available, but it is not currently enabled.
491 echo 1 >/sys/kernel/mm/ksm/run
492 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
494 If you enable it, you will save 20-60% of netdata memory.
499 ksm_is_not_available() {
504 I see you do not have kernel memory de-duper (called Kernel Same-page
505 Merging, or KSM) available.
507 To enable it, you need a kernel built with CONFIG_KSM=y
509 If you can have it, you will save 20-60% of netdata memory.
514 if [ -f "/sys/kernel/mm/ksm/run" ]
516 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
518 ksm_is_available_but_disabled
524 # -----------------------------------------------------------------------------
525 # Check for version.txt
527 if [ ! -s web/version.txt ]
531 VERSION UPDATE CHECK:
533 The way you downloaded netdata, we cannot find its version.
534 This means the Update check on the dashboard, will not work.
536 If you want to have version update check, please re-install it
537 following the procedure in:
539 https://github.com/firehol/netdata/wiki/Installation
545 # -----------------------------------------------------------------------------
546 # Keep un-install info
548 cat >netdata-uninstaller.sh <<UNINSTALL
551 # this script will uninstall netdata
553 if [ "\$1" != "--force" ]
555 echo >&2 "This script will REMOVE netdata from your system."
556 echo >&2 "Run it again with --force to do it."
560 echo >&2 "Stopping a possibly running netdata..."
565 if [ ! -z "\$1" -a -d "\$1" ]
568 echo "Deleting directory '\$1' ..."
573 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
575 # installation prefix was given
577 deletedir "${NETDATA_PREFIX}"
580 # installation prefix was NOT given
582 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
584 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
585 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
588 deletedir "${NETDATA_PREFIX}/etc/netdata"
589 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
590 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
591 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
592 deletedir "${NETDATA_PREFIX}/var/log/netdata"
595 getent passwd netdata > /dev/null
599 echo "You may also want to remove the user netdata"
601 echo " userdel netdata"
604 getent group netdata > /dev/null
608 echo "You may also want to remove the group netdata"
610 echo " groupdel netdata"
614 chmod 750 netdata-uninstaller.sh
616 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"