8 This script will build and install netdata to your system.
10 By default netdata will be installed as any other package.
11 If you want to install it to another directory, run me
14 $0 --install /path/to/install
16 A new directory called netdata will be created as
18 /path/to/install/netdata
23 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
26 echo >&2 "You have to run netdata are root."
27 echo >&2 "The netdata daemon will drop priviliges"
28 echo >&2 "but you have to start it as root."
34 if [ "$1" = "--install" ]
36 NETDATA_PREFIX="${2}/netdata"
40 if [ ! -z "${NETDATA_PREFIX}" ]
42 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
44 read -p "Press ENTER to build and install netdata to your system > "
48 [ -f /etc/profile ] && . /etc/profile
53 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55 We are very sorry! NetData failed to build...
57 You many need to check these:
59 1. The package zlib1g-dev has to be installed.
61 2. You need basic build tools installed, like:
63 gcc autoconf automake pgk-config
65 3. If your system cannot find ZLIB, although it is installed
66 run me with the option: --zlib-is-really-here
68 If you still cannot get it to build, ask for help at github:
70 https://github.com/firehol/netdata/issues
79 printf >&2 ":-----------------------------------------------------------------------------\n"
80 printf >&2 "Running command:\n"
82 printf >&2 "%q " "${@}"
89 if [ "$1" = "--zlib-is-really-here" ]
92 echo >&2 "ok, assuming zlib is really installed."
93 export ZLIB_CFLAGS=" "
94 export ZLIB_LIBS="-lz"
99 echo >&2 "Running ./autogen.sh ..."
100 run ./autogen.sh || exit 1
102 echo >&2 "Running ./configure ..."
104 --prefix="${NETDATA_PREFIX}/usr" \
105 --sysconfdir="${NETDATA_PREFIX}/etc" \
106 --localstatedir="${NETDATA_PREFIX}/var" \
107 --with-zlib --with-math --with-user=netdata \
108 CFLAGS="-O3" || exit 1
110 # remove the build_error hook
113 if [ -f src/netdata ]
115 echo >&2 "Cleaning a possibly old compilation ..."
119 echo >&2 "Compiling netdata ..."
122 echo >&2 "Installing netdata ..."
123 run make install || exit 1
125 echo >&2 "Adding netdata user group ..."
126 getent group netdata > /dev/null || run groupadd -r netdata
128 echo >&2 "Adding netdata user account ..."
129 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
133 # -----------------------------------------------------------------------------
134 # load options from the configuration file
136 # create an empty config if it does not exist
137 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
139 # function to extract values from the config file
141 local key="${1}" value="${2}" line=
143 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
145 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
146 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
154 [ ! "${UID}" = "0" ] && defuser="${USER}"
155 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
159 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
163 NETDATA_PORT="$( config_option "port" ${defport} )"
166 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
167 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
168 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
169 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
172 # -----------------------------------------------------------------------------
173 # prepare the directories
175 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
176 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
180 echo >&2 "Creating directory '${x}'"
181 run mkdir -p "${x}" || exit 1
183 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
184 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
187 # fix apps.plugin to be setuid to root
188 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
189 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
192 # -----------------------------------------------------------------------------
193 # stop a running netdata
195 printf >&2 "Stopping a (possibly) running netdata..."
202 echo >&2 "Cannot stop the running netdata."
207 run killall netdata 2>/dev/null
209 test $ret -eq 0 && printf >&2 "." && sleep 2
214 # -----------------------------------------------------------------------------
217 echo >&2 "Starting netdata..."
218 run ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
223 echo >&2 "SORRY! FAILED TO START NETDATA!"
226 echo >&2 "OK. NetData Started!"
230 # -----------------------------------------------------------------------------
231 # save a config file, if it is not already there
233 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
235 echo >&2 "Downloading default configuration from netdata..."
238 # remove a possibly obsolete download
239 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
242 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
246 if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
248 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
252 if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
254 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
255 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
257 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
258 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
260 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
261 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
268 -------------------------------------------------------------------------------
270 ok. NetData is installed and is running.
272 Hit http://localhost:${NETDATA_PORT}/ from your browser.
274 To stop netdata, just kill it, with:
278 To start it, just run it:
280 ${NETDATA_PREFIX}/usr/sbin/netdata