3 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
6 echo >&2 "You have to run netdata are root."
7 echo >&2 "The netdata daemon will drop priviliges"
8 echo >&2 "but you have to start it as root."
10 echo >&2 "If netdata is not already installed,"
11 echo >&2 "this script will also build and install"
12 echo >&2 "netdata to your system."
18 [ -f /etc/profile ] && . /etc/profile
23 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25 We are very sorry! NetData failed to build...
27 You many need to check these:
29 1. The package zlib1g-dev has to be installed.
31 2. You need basic build tools installed, like: gcc, autoconf,
32 pgk-config, automake, etc.
34 3. If your system cannot find ZLIB, although it is installed
35 run me with the option: --zlib-is-really-here
37 If you still cannot get it to build, ask for help at github:
39 https://github.com/firehol/netdata/issues
48 printf >&2 ":-----------------------------------------------------------------------------\n"
49 printf >&2 "Running command:\n"
51 printf >&2 "%q " "${@}"
58 if [ "$1" = "--zlib-is-really-here" ]
61 echo >&2 "ok, assuming zlib is really installed."
62 export ZLIB_CFLAGS=" "
63 export ZLIB_LIBS="-lz"
66 if [ ! -f src/Makefile ]
68 read -p "Netdata is not configured. Press ENTER to configure it > "
72 echo >&2 "Running ./autogen.sh ..."
73 run ./autogen.sh || exit 1
75 echo >&2 "Running ./configure ..."
76 run ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-zlib --with-math --with-user=netdata CFLAGS="-march=native -O3" || exit 1
78 # remove the build_error hook
83 echo >&2 "Cleaning a possibly old compilation ..."
88 echo >&2 "Compiling netdata ..."
91 echo >&2 "Installing netdata ..."
94 echo >&2 "Adding netdata user group ..."
95 getent group netdata > /dev/null || run groupadd -r netdata
97 echo >&2 "Adding netdata user account ..."
98 getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
102 # -----------------------------------------------------------------------------
103 # load options from the configuration file
105 # create an empty config if it does not exist
106 [ ! -f /etc/netdata/netdata.conf ] && touch /etc/netdata/netdata.conf
108 # function to extract values from the config file
110 local key="${1}" value="${2}" line=
112 if [ -s "/etc/netdata/netdata.conf" ]
114 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "/etc/netdata/netdata.conf" | head -n 1 )"
115 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
123 [ ! "${UID}" = "0" ] && defuser="${USER}"
124 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
128 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
132 NETDATA_PORT="$( config_option "port" ${defport} )"
135 NETDATA_CACHE_DIR="$( config_option "cache directory" "/var/cache/netdata" )"
136 NETDATA_WEB_DIR="$( config_option "web files directory" "/usr/share/netdata/web" )"
137 NETDATA_LOG_DIR="$( config_option "log directory" "/var/log/netdata" )"
138 NETDATA_CONF_DIR="$( config_option "config directory" "/etc/netdata" )"
141 # -----------------------------------------------------------------------------
142 # prepare the directories
144 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
145 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
149 echo >&2 "Creating directory '${x}'"
150 run mkdir -p "${x}" || exit 1
152 run chown -R "${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
153 run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
156 # fix apps.plugin to be setuid to root
157 run chown root '/usr/libexec/netdata/plugins.d/apps.plugin' && run chmod 4755 '/usr/libexec/netdata/plugins.d/apps.plugin'
160 # -----------------------------------------------------------------------------
161 # stop a running netdata
163 printf >&2 "Stopping a (possibly) running netdata..."
170 echo >&2 "Cannot stop the running netdata."
175 killall netdata 2>/dev/null
177 test $ret -eq 0 && printf >&2 "." && sleep 2
182 # -----------------------------------------------------------------------------
185 echo >&2 "Starting netdata..."
191 echo >&2 "SORRY! FAILED TO START NETDATA!"
194 echo >&2 "OK. NetData Started!"
198 # -----------------------------------------------------------------------------
199 # save a config file, if it is not already there
201 if [ ! -s /etc/netdata/netdata.conf ]
203 echo >&2 "Downloading default configuration from netdata..."
206 # remove a possibly obsolete download
207 [ -f /etc/netdata/netdata.conf.new ] && rm /etc/netdata/netdata.conf.new
210 wget 2>/dev/null -O /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
214 if [ $ret -ne 0 -o ! -s /etc/netdata/netdata.conf.net ]
216 curl -s -o /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
220 if [ $ret -eq 0 -a -s /etc/netdata/netdata.conf.new ]
222 mv /etc/netdata/netdata.conf.new /etc/netdata/netdata.conf
223 echo >&2 "New configuration saved for you to edit at /etc/netdata/netdata.conf"
225 chown "${NETDATA_USER}" /etc/netdata/netdata.conf
226 chmod 0664 /etc/netdata/netdata.conf
228 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
229 [ -f /etc/netdata/netdata.conf.new ] && rm /etc/netdata/netdata.conf.new
236 -------------------------------------------------------------------------------
238 ok. NetData is installed and is running.
240 Hit http://localhost:${NETDATA_PORT}/ from your browser.
242 To stop netdata, just kill it, with:
246 To start it, just run it: