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."
130 if [ ${DONOTWAIT} -eq 0 ]
132 if [ ! -z "${NETDATA_PREFIX}" ]
134 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
136 read -p "Press ENTER to build and install netdata to your system > "
141 [ -f /etc/profile ] && . /etc/profile
146 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148 Sorry! NetData failed to build...
150 You many need to check these:
152 1. The package zlib1g-dev has to be installed.
154 2. You need basic build tools installed, like:
156 gcc make autoconf automake pkg-config
158 3. If your system cannot find ZLIB, although it is installed
159 run me with the option: --zlib-is-really-here
161 If you still cannot get it to build, ask for help at github:
163 https://github.com/firehol/netdata/issues
172 printf >&2 ":-----------------------------------------------------------------------------\n"
173 printf >&2 "Running command:\n"
175 printf >&2 "%q " "${@}"
182 if [ ${ZLIB_IS_HERE} -eq 1 ]
185 echo >&2 "ok, assuming zlib is really installed."
186 export ZLIB_CFLAGS=" "
187 export ZLIB_LIBS="-lz"
190 trap build_error EXIT
192 echo >&2 "Running ./autogen.sh ..."
193 run ./autogen.sh || exit 1
195 echo >&2 "Running ./configure ..."
197 --prefix="${NETDATA_PREFIX}/usr" \
198 --sysconfdir="${NETDATA_PREFIX}/etc" \
199 --localstatedir="${NETDATA_PREFIX}/var" \
200 --with-zlib --with-math --with-user=netdata \
201 CFLAGS="${CFLAGS}" || exit 1
203 # remove the build_error hook
206 if [ -f src/netdata ]
208 echo >&2 "Cleaning a possibly old compilation ..."
212 echo >&2 "Compiling netdata ..."
215 echo >&2 "Installing netdata ..."
216 run make install || exit 1
218 echo >&2 "Adding netdata user group ..."
219 getent group netdata > /dev/null || run groupadd -r netdata
221 echo >&2 "Adding netdata user account ..."
222 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
226 # -----------------------------------------------------------------------------
227 # load options from the configuration file
229 # create an empty config if it does not exist
230 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
232 # function to extract values from the config file
234 local key="${1}" value="${2}" line=
236 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
238 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
239 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
247 [ ! "${UID}" = "0" ] && defuser="${USER}"
248 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
252 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
256 NETDATA_PORT="$( config_option "port" ${defport} )"
259 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
260 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
261 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
262 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
265 # -----------------------------------------------------------------------------
266 # prepare the directories
268 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
269 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
273 echo >&2 "Creating directory '${x}'"
274 run mkdir -p "${x}" || exit 1
276 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
277 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
280 # fix apps.plugin to be setuid to root
281 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
282 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
285 # -----------------------------------------------------------------------------
286 # check if we can re-start netdata
288 if [ ${DONOTSTART} -eq 1 ]
290 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
292 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
293 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
294 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
295 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
297 echo >&2 "OK. It is now installed and ready."
301 # -----------------------------------------------------------------------------
302 # stop a running netdata
305 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
306 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
311 printf >&2 "Stopping a (possibly) running netdata..."
318 echo >&2 "Cannot stop the running netdata."
324 pid=$(cat /var/run/netdata.pid 2>/dev/null)
325 # backwards compatibility
326 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
328 isnetdata $pid || pid=
331 run kill $pid 2>/dev/null
334 run killall netdata 2>/dev/null
338 test $ret -eq 0 && printf >&2 "." && sleep 2
343 # -----------------------------------------------------------------------------
346 echo >&2 "Starting netdata..."
347 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile /var/run/netdata.pid "${@}"
352 echo >&2 "SORRY! FAILED TO START NETDATA!"
355 echo >&2 "OK. NetData Started!"
359 # -----------------------------------------------------------------------------
360 # save a config file, if it is not already there
362 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
364 echo >&2 "Downloading default configuration from netdata..."
367 # remove a possibly obsolete download
368 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
370 # disable a proxy to get data from the local netdata
375 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
379 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
381 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
385 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
387 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
388 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
390 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
391 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
393 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
394 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
398 # -----------------------------------------------------------------------------
403 -------------------------------------------------------------------------------
405 ok. NetData is installed and is running.
407 Hit http://localhost:${NETDATA_PORT}/ from your browser.
409 To stop netdata, just kill it, with:
413 To start it, just run it:
415 ${NETDATA_PREFIX}/usr/sbin/netdata
421 # -----------------------------------------------------------------------------
424 ksm_is_available_but_disabled() {
429 I see you have kernel memory de-duper (called Kernel Same-page Merging,
430 or KSM) available, but it is not currently enabled.
434 echo 1 >/sys/kernel/mm/ksm/run
435 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
437 If you enable it, you will save 20-60% of netdata memory.
442 ksm_is_not_available() {
447 I see you do not have kernel memory de-duper (called Kernel Same-page
448 Merging, or KSM) available.
450 To enable it, you need a kernel built with CONFIG_KSM=y
452 If you can have it, you will save 20-60% of netdata memory.
457 if [ -f "/sys/kernel/mm/ksm/run" ]
459 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
461 ksm_is_available_but_disabled
467 # -----------------------------------------------------------------------------
468 # Check for version.txt
470 if [ ! -s web/version.txt ]
474 VERSION UPDATE CHECK:
476 The way you downloaded netdata, we cannot find its version.
477 This means the Update check on the dashboard, will not work.
479 If you want to have version update check, please re-install it
480 following the procedure in:
482 https://github.com/firehol/netdata/wiki/Installation
488 # -----------------------------------------------------------------------------
489 # Keep un-install info
491 cat >netdata-uninstaller.sh <<UNINSTALL
494 # this script will uninstall netdata
496 if [ "\$1" != "--force" ]
498 echo >&2 "This script will REMOVE netdata from your system."
499 echo >&2 "Run it again with --force to do it."
503 echo >&2 "Stopping a possibly running netdata..."
508 if [ ! -z "\$1" -a -d "\$1" ]
511 echo "Deleting directory '\$1' ..."
516 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
518 # installation prefix was given
520 deletedir "${NETDATA_PREFIX}"
523 # installation prefix was NOT given
525 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
527 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
528 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
531 deletedir "${NETDATA_PREFIX}/etc/netdata"
532 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
533 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
534 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
535 deletedir "${NETDATA_PREFIX}/var/log/netdata"
538 getent passwd netdata > /dev/null
542 echo "You may also want to remove the user netdata"
544 echo " userdel netdata"
547 getent group netdata > /dev/null
551 echo "You may also want to remove the group netdata"
553 echo " groupdel netdata"
557 chmod 750 netdata-uninstaller.sh
559 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"