6 This script will build and install netdata to your system.
8 By default netdata will be installed as any other package.
9 If you want to install it to another directory, run me
12 $0 --install /path/to/install
14 A new directory called netdata will be created as
16 /path/to/install/netdata
21 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
24 echo >&2 "You have to run netdata are root."
25 echo >&2 "The netdata daemon will drop priviliges"
26 echo >&2 "but you have to start it as root."
32 if [ "$1" = "--install" ]
34 NETDATA_PREFIX="${2}/netdata"
38 if [ ! -z "${NETDATA_PREFIX}" ]
40 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
42 read -p "Press ENTER to build and install netdata to your system > "
46 [ -f /etc/profile ] && . /etc/profile
51 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53 We are very sorry! NetData failed to build...
55 You many need to check these:
57 1. The package zlib1g-dev has to be installed.
59 2. You need basic build tools installed, like:
61 gcc autoconf automake pgk-config
63 3. If your system cannot find ZLIB, although it is installed
64 run me with the option: --zlib-is-really-here
66 If you still cannot get it to build, ask for help at github:
68 https://github.com/firehol/netdata/issues
77 printf >&2 ":-----------------------------------------------------------------------------\n"
78 printf >&2 "Running command:\n"
80 printf >&2 "%q " "${@}"
87 if [ "$1" = "--zlib-is-really-here" ]
90 echo >&2 "ok, assuming zlib is really installed."
91 export ZLIB_CFLAGS=" "
92 export ZLIB_LIBS="-lz"
97 echo >&2 "Running ./autogen.sh ..."
98 run ./autogen.sh || exit 1
100 echo >&2 "Running ./configure ..."
102 --prefix="${NETDATA_PREFIX}/usr" \
103 --sysconfdir="${NETDATA_PREFIX}/etc" \
104 --localstatedir="${NETDATA_PREFIX}/var" \
105 --with-zlib --with-math --with-user=netdata \
106 CFLAGS="-march=native -O3" || exit 1
108 # remove the build_error hook
111 if [ -f src/netdata ]
113 echo >&2 "Cleaning a possibly old compilation ..."
117 echo >&2 "Compiling netdata ..."
120 echo >&2 "Installing netdata ..."
121 run make install || exit 1
123 echo >&2 "Adding netdata user group ..."
124 getent group netdata > /dev/null || run groupadd -r netdata
126 echo >&2 "Adding netdata user account ..."
127 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
131 # -----------------------------------------------------------------------------
132 # load options from the configuration file
134 # create an empty config if it does not exist
135 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
137 # function to extract values from the config file
139 local key="${1}" value="${2}" line=
141 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
143 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
144 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
152 [ ! "${UID}" = "0" ] && defuser="${USER}"
153 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
157 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
161 NETDATA_PORT="$( config_option "port" ${defport} )"
164 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
165 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
166 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
167 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
170 # -----------------------------------------------------------------------------
171 # prepare the directories
173 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
174 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
178 echo >&2 "Creating directory '${x}'"
179 run mkdir -p "${x}" || exit 1
181 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
182 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
185 # fix apps.plugin to be setuid to root
186 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
187 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
190 # -----------------------------------------------------------------------------
191 # stop a running netdata
193 printf >&2 "Stopping a (possibly) running netdata..."
200 echo >&2 "Cannot stop the running netdata."
205 run killall netdata 2>/dev/null
207 test $ret -eq 0 && printf >&2 "." && sleep 2
212 # -----------------------------------------------------------------------------
215 echo >&2 "Starting netdata..."
216 run ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
221 echo >&2 "SORRY! FAILED TO START NETDATA!"
224 echo >&2 "OK. NetData Started!"
228 # -----------------------------------------------------------------------------
229 # save a config file, if it is not already there
231 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
233 echo >&2 "Downloading default configuration from netdata..."
236 # remove a possibly obsolete download
237 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
240 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
244 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
246 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
250 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
252 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
253 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
255 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
256 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
258 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
259 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
266 -------------------------------------------------------------------------------
268 ok. NetData is installed and is running.
270 Hit http://localhost:${NETDATA_PORT}/ from your browser.
272 To stop netdata, just kill it, with:
276 To start it, just run it:
278 ${NETDATA_PREFIX}/usr/sbin/netdata