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 By default netdata will be installed as any other package:
101 - the daemon at /usr/sbin/netdata
102 - config files at /etc/netdata
103 - web files at /usr/share/web/netdata
104 - plugins at /usr/libexec/netdata
105 - cache files at /var/cache/netdata
106 - log files at /var/log/netdata
108 If you want to install it to another directory, run the
111 $ME --install /path/to/install
113 A new directory called netdata will be created as
115 /path/to/install/netdata
117 and all of netdata will be installed into it.
118 Nothing will be touched on your system.
120 This installer accepts more options.
121 Run it with --help for help.
125 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
128 echo >&2 "You have to run netdata as root."
129 echo >&2 "The netdata daemon will drop priviliges"
130 echo >&2 "but you have to start it as root."
135 if [ ${DONOTWAIT} -eq 0 ]
137 if [ ! -z "${NETDATA_PREFIX}" ]
139 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
141 read -p "Press ENTER to build and install netdata to your system > "
146 [ -f /etc/profile ] && . /etc/profile
151 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
153 Sorry! NetData failed to build...
155 You many need to check these:
157 1. The package zlib1g-dev has to be installed.
159 2. You need basic build tools installed, like:
161 gcc make autoconf automake pkg-config
163 3. If your system cannot find ZLIB, although it is installed
164 run me with the option: --zlib-is-really-here
166 If you still cannot get it to build, ask for help at github:
168 https://github.com/firehol/netdata/issues
177 printf >&2 ":-----------------------------------------------------------------------------\n"
178 printf >&2 "Running command:\n"
180 printf >&2 "%q " "${@}"
187 if [ ${ZLIB_IS_HERE} -eq 1 ]
190 echo >&2 "ok, assuming zlib is really installed."
191 export ZLIB_CFLAGS=" "
192 export ZLIB_LIBS="-lz"
195 trap build_error EXIT
197 echo >&2 "Running ./autogen.sh ..."
198 run ./autogen.sh || exit 1
200 echo >&2 "Running ./configure ..."
202 --prefix="${NETDATA_PREFIX}/usr" \
203 --sysconfdir="${NETDATA_PREFIX}/etc" \
204 --localstatedir="${NETDATA_PREFIX}/var" \
205 --with-zlib --with-math --with-user=netdata \
206 CFLAGS="${CFLAGS}" || exit 1
208 # remove the build_error hook
211 if [ -f src/netdata ]
213 echo >&2 "Cleaning a possibly old compilation ..."
217 echo >&2 "Compiling netdata ..."
220 echo >&2 "Installing netdata ..."
221 run make install || exit 1
223 echo >&2 "Adding netdata user group ..."
224 getent group netdata > /dev/null || run groupadd -r netdata
226 echo >&2 "Adding netdata user account ..."
227 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
231 # -----------------------------------------------------------------------------
232 # load options from the configuration file
234 # create an empty config if it does not exist
235 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
237 # function to extract values from the config file
239 local key="${1}" value="${2}" line=
241 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
243 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
244 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
252 [ ! "${UID}" = "0" ] && defuser="${USER}"
253 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
257 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
261 NETDATA_PORT="$( config_option "port" ${defport} )"
264 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
265 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
266 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
267 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
270 # -----------------------------------------------------------------------------
271 # prepare the directories
273 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
274 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
278 echo >&2 "Creating directory '${x}'"
279 run mkdir -p "${x}" || exit 1
281 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
282 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
285 # fix apps.plugin to be setuid to root
286 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
287 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
290 # -----------------------------------------------------------------------------
291 # check if we can re-start netdata
293 if [ ${DONOTSTART} -eq 1 ]
295 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
297 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
298 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
299 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
300 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
302 echo >&2 "OK. It is now installed and ready."
306 # -----------------------------------------------------------------------------
307 # stop a running netdata
309 printf >&2 "Stopping a (possibly) running netdata..."
316 echo >&2 "Cannot stop the running netdata."
321 run killall netdata 2>/dev/null
323 test $ret -eq 0 && printf >&2 "." && sleep 2
328 # -----------------------------------------------------------------------------
331 echo >&2 "Starting netdata..."
332 run ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
337 echo >&2 "SORRY! FAILED TO START NETDATA!"
340 echo >&2 "OK. NetData Started!"
344 # -----------------------------------------------------------------------------
345 # save a config file, if it is not already there
347 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
349 echo >&2 "Downloading default configuration from netdata..."
352 # remove a possibly obsolete download
353 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
356 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
360 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
362 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
366 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
368 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
369 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
371 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
372 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
374 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
375 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
382 -------------------------------------------------------------------------------
384 ok. NetData is installed and is running.
386 Hit http://localhost:${NETDATA_PORT}/ from your browser.
388 To stop netdata, just kill it, with:
392 To start it, just run it:
394 ${NETDATA_PREFIX}/usr/sbin/netdata