5 # you can set CFLAGS before running installer
17 ${ME} <installer options>
19 Valid <installer options> are:
21 --install /PATH/TO/INSTALL
23 If your give: --install /opt
24 netdata will be installed in /opt/netdata
28 Do not (re)start netdata.
33 Do not wait for the user to press ENTER.
34 Start immediately building it.
38 If you get errors about missing zlib,
39 but you know it is available,
40 you have a broken pkg-config.
41 Use this option to allow it continue
42 without checking pkg-config.
44 Netdata will by default be compiled with gcc optimization -O3
45 If you need to pass different CFLAGS, use something like this:
47 CFLAGS="<gcc options>" $ME <installer options>
49 For the installer to complete successfully, you will need
50 these packages installed:
52 gcc make autoconf automake pkg-config zlib1g-dev
54 For the plugins, you will at least need:
63 if [ "$1" = "--install" ]
65 NETDATA_PREFIX="${2}/netdata"
67 elif [ "$1" = "--zlib-is-really-here" ]
71 elif [ "$1" = "--dont-start-it" ]
75 elif [ "$1" = "--dont-wait" ]
79 elif [ "$1" = "--help" -o "$1" = "-h" ]
86 echo >&2 "I cannot understand option '$1'."
95 Nice to see you are giving it a try!
97 You are about to build and install netdata to your system.
99 It will be installed at these locations:
101 - the daemon at ${NETDATA_PREFIX}/usr/sbin/netdata
102 - config files at ${NETDATA_PREFIX}/etc/netdata
103 - web files at ${NETDATA_PREFIX}/usr/share/netdata
104 - plugins at ${NETDATA_PREFIX}/usr/libexec/netdata
105 - cache files at ${NETDATA_PREFIX}/var/cache/netdata
106 - log files at ${NETDATA_PREFIX}/var/log/netdata
108 This installer allows you to change the installation path.
109 Press Control-C and run the same command with --help for help.
113 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
116 echo >&2 "You have to run netdata as root."
117 echo >&2 "The netdata daemon will drop priviliges"
118 echo >&2 "but you have to start it as root."
123 if [ ${DONOTWAIT} -eq 0 ]
125 if [ ! -z "${NETDATA_PREFIX}" ]
127 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
129 read -p "Press ENTER to build and install netdata to your system > "
134 [ -f /etc/profile ] && . /etc/profile
139 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141 Sorry! NetData failed to build...
143 You many need to check these:
145 1. The package zlib1g-dev has to be installed.
147 2. You need basic build tools installed, like:
149 gcc make autoconf automake pkg-config
151 3. If your system cannot find ZLIB, although it is installed
152 run me with the option: --zlib-is-really-here
154 If you still cannot get it to build, ask for help at github:
156 https://github.com/firehol/netdata/issues
165 printf >&2 ":-----------------------------------------------------------------------------\n"
166 printf >&2 "Running command:\n"
168 printf >&2 "%q " "${@}"
175 if [ ${ZLIB_IS_HERE} -eq 1 ]
178 echo >&2 "ok, assuming zlib is really installed."
179 export ZLIB_CFLAGS=" "
180 export ZLIB_LIBS="-lz"
183 trap build_error EXIT
185 echo >&2 "Running ./autogen.sh ..."
186 run ./autogen.sh || exit 1
188 echo >&2 "Running ./configure ..."
190 --prefix="${NETDATA_PREFIX}/usr" \
191 --sysconfdir="${NETDATA_PREFIX}/etc" \
192 --localstatedir="${NETDATA_PREFIX}/var" \
193 --with-zlib --with-math --with-user=netdata \
194 CFLAGS="${CFLAGS}" || exit 1
196 # remove the build_error hook
199 if [ -f src/netdata ]
201 echo >&2 "Cleaning a possibly old compilation ..."
205 echo >&2 "Compiling netdata ..."
208 echo >&2 "Installing netdata ..."
209 run make install || exit 1
211 echo >&2 "Adding netdata user group ..."
212 getent group netdata > /dev/null || run groupadd -r netdata
214 echo >&2 "Adding netdata user account ..."
215 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
219 # -----------------------------------------------------------------------------
220 # load options from the configuration file
222 # create an empty config if it does not exist
223 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
225 # function to extract values from the config file
227 local key="${1}" value="${2}" line=
229 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
231 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
232 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
240 [ ! "${UID}" = "0" ] && defuser="${USER}"
241 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
245 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
249 NETDATA_PORT="$( config_option "port" ${defport} )"
252 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
253 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
254 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
255 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
258 # -----------------------------------------------------------------------------
259 # prepare the directories
261 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
262 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
266 echo >&2 "Creating directory '${x}'"
267 run mkdir -p "${x}" || exit 1
269 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
270 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
273 # fix apps.plugin to be setuid to root
274 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
275 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
278 # -----------------------------------------------------------------------------
279 # check if we can re-start netdata
281 if [ ${DONOTSTART} -eq 1 ]
283 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
285 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
286 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
287 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
288 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
290 echo >&2 "OK. It is now installed and ready."
294 # -----------------------------------------------------------------------------
295 # stop a running netdata
298 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
299 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
304 printf >&2 "Stopping a (possibly) running netdata..."
311 echo >&2 "Cannot stop the running netdata."
317 pid=$(cat /var/run/netdata.pid 2>/dev/null)
318 # backwards compatibility
319 [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
321 isnetdata $pid || pid=
324 run kill $pid 2>/dev/null
327 run killall netdata 2>/dev/null
331 test $ret -eq 0 && printf >&2 "." && sleep 2
336 # -----------------------------------------------------------------------------
339 echo >&2 "Starting netdata..."
340 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile /var/run/netdata.pid "${@}"
345 echo >&2 "SORRY! FAILED TO START NETDATA!"
348 echo >&2 "OK. NetData Started!"
352 # -----------------------------------------------------------------------------
353 # save a config file, if it is not already there
355 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
357 echo >&2 "Downloading default configuration from netdata..."
360 # remove a possibly obsolete download
361 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
363 # disable a proxy to get data from the local netdata
368 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
372 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
374 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
378 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
380 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
381 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
383 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
384 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
386 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
387 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
394 -------------------------------------------------------------------------------
396 ok. NetData is installed and is running.
398 Hit http://localhost:${NETDATA_PORT}/ from your browser.
400 To stop netdata, just kill it, with:
404 To start it, just run it:
406 ${NETDATA_PREFIX}/usr/sbin/netdata
412 ksm_is_available_but_disabled() {
417 I see you have kernel memory de-duper (called Kernel Same-page Merging,
418 or KSM) available, but it is not currently enabled.
422 echo 1 >/sys/kernel/mm/ksm/run
423 echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
425 If you enable it, you will save 20-60% of netdata memory.
430 ksm_is_not_available() {
435 I see you do not have kernel memory de-duper (called Kernel Same-page
436 Merging, or KSM) available.
438 To enable it, you need a kernel built with CONFIG_KSM=y
440 If you can have it, you will save 20-60% of netdata memory.
445 if [ -f "/sys/kernel/mm/ksm/run" ]
447 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
449 ksm_is_available_but_disabled