@cryptotaxi247 / netdata-1 / commits / 1b68ee4b7

updated installer

Costa Tsaousis (ktsaou) committed Nov 17, 2015 at 22:06 UTC 1b68ee4b7b809471f52a63708d4fc020dbc93ee0
2 files changed +79 -50
README.md
+3 -4
@@ -173,10 +173,9 @@ cd netdata.git
173 The script `netdata-installer.sh` will build netdata and install it to your system.
174
175 Once the installer completes, the file `/etc/netdata/netdata.conf` will be created.
176 -You can edit this file to set options.
177 -To apply the changes you made, you have to restart netdata.
176 +You can edit this file to set options. To apply the changes you made, you have to restart netdata.
177
179 -- You can start netdata by executing it with `netdata` (the installer will also start it).
178 +- You can start netdata by executing it with `/usr/sbin/netdata` (the installer will also start it).
179
180 - You can stop netdata by killing it with `killall netdata`.
181 You can stop and start netdata at any point. Netdata saves on exit its round robbin
@@ -190,4 +189,4 @@ To access the web site for all graphs, go to:
189
190 You can get the running config file at any time, by accessing `http://127.0.0.1:19999/netdata.conf`.
191
193 -To start it at boot, just run `netdata` from your `/etc/rc.local` or equivalent.
192 +To start it at boot, just run `/usr/sbin/netdata` from your `/etc/rc.local` or equivalent.
netdata-installer.sh
+76 -46
@@ -1,5 +1,23 @@
1 #!/bin/bash
2
3 +cat <<BANNER
4 +
5 +
6 +This script will build and install netdata to your system.
7 +
8 +By default netdata will be installed as any other package.
9 +If you want to install it to another directory, run me
10 +with the option:
11 +
12 +$0 --install /path/to/install
13 +
14 +A new directory called netdata will be created as
15 +
16 +/path/to/install/netdata
17 +
18 +
19 +BANNER
20 +
21 if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
22 then
23 echo >&2
@@ -7,13 +25,23 @@ if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
25 echo >&2 "The netdata daemon will drop priviliges"
26 echo >&2 "but you have to start it as root."
27 echo >&2
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."
13 - echo >&2
28 exit 1
29 fi
30
31 +NETDATA_PREFIX=
32 +if [ "$1" = "--install" ]
33 + then
34 + NETDATA_PREFIX="${2}/netdata"
35 + shift 2
36 +fi
37 +
38 +if [ ! -z "${NETDATA_PREFIX}" ]
39 + then
40 + read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
41 +else
42 + read -p "Press ENTER to build and install netdata to your system > "
43 +fi
44 +
45 # reload the profile
46 [ -f /etc/profile ] && . /etc/profile
47
@@ -28,8 +56,9 @@ You many need to check these:
56
57 1. The package zlib1g-dev has to be installed.
58
31 -2. You need basic build tools installed, like: gcc, autoconf,
32 - pgk-config, automake, etc.
59 +2. You need basic build tools installed, like:
60 +
61 + gcc autoconf automake pgk-config
62
63 3. If your system cannot find ZLIB, although it is installed
64 run me with the option: --zlib-is-really-here
@@ -63,33 +92,33 @@ if [ "$1" = "--zlib-is-really-here" ]
92 export ZLIB_LIBS="-lz"
93 fi
94
66 -if [ ! -f src/Makefile ]
67 - then
68 - read -p "Netdata is not configured. Press ENTER to configure it > "
69 -
70 - trap build_error EXIT
95 +trap build_error EXIT
96
72 - echo >&2 "Running ./autogen.sh ..."
73 - run ./autogen.sh || exit 1
97 +echo >&2 "Running ./autogen.sh ..."
98 +run ./autogen.sh || exit 1
99
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
100 +echo >&2 "Running ./configure ..."
101 +run ./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
107
78 - # remove the build_error hook
79 - trap - EXIT
108 +# remove the build_error hook
109 +trap - EXIT
110
81 - if [ -f src/netdata ]
82 - then
83 - echo >&2 "Cleaning a possibly old compilation ..."
84 - make clean
85 - fi
111 +if [ -f src/netdata ]
112 + then
113 + echo >&2 "Cleaning a possibly old compilation ..."
114 + run make clean
115 fi
116
117 echo >&2 "Compiling netdata ..."
118 run make || exit 1
119
120 echo >&2 "Installing netdata ..."
92 -run make install
121 +run make install || exit 1
122
123 echo >&2 "Adding netdata user group ..."
124 getent group netdata > /dev/null || run groupadd -r netdata
@@ -103,15 +132,15 @@ getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sb
132 # load options from the configuration file
133
134 # create an empty config if it does not exist
106 -[ ! -f /etc/netdata/netdata.conf ] && touch /etc/netdata/netdata.conf
135 +[ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
136
137 # function to extract values from the config file
138 config_option() {
139 local key="${1}" value="${2}" line=
140
112 - if [ -s "/etc/netdata/netdata.conf" ]
141 + if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
142 then
114 - line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "/etc/netdata/netdata.conf" | head -n 1 )"
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" )"
145 fi
146
@@ -132,10 +161,10 @@ defport=19999
161 NETDATA_PORT="$( config_option "port" ${defport} )"
162
163 # directories
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" )"
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" )"
168
169
170 # -----------------------------------------------------------------------------
@@ -149,12 +178,13 @@ do
178 echo >&2 "Creating directory '${x}'"
179 run mkdir -p "${x}" || exit 1
180 fi
152 - run chown -R "${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
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..."
183 done
184
185 # 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'
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"
188
189
190 # -----------------------------------------------------------------------------
@@ -172,7 +202,7 @@ do
202 fi
203
204 count=$((count + 1))
175 - killall netdata 2>/dev/null
205 + run killall netdata 2>/dev/null
206 ret=$?
207 test $ret -eq 0 && printf >&2 "." && sleep 2
208 done
@@ -183,7 +213,7 @@ echo >&2
213 # run netdata
214
215 echo >&2 "Starting netdata..."
186 -netdata "${@}"
216 +run ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
217
218 if [ $? -ne 0 ]
219 then
@@ -198,35 +228,35 @@ fi
228 # -----------------------------------------------------------------------------
229 # save a config file, if it is not already there
230
201 -if [ ! -s /etc/netdata/netdata.conf ]
231 +if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
232 then
233 echo >&2 "Downloading default configuration from netdata..."
234 sleep 5
235
236 # remove a possibly obsolete download
207 - [ -f /etc/netdata/netdata.conf.new ] && rm /etc/netdata/netdata.conf.new
237 + [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
238
239 # try wget
210 - wget 2>/dev/null -O /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
240 + wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
241 ret=$?
242
243 # try curl
214 - if [ $ret -ne 0 -o ! -s /etc/netdata/netdata.conf.net ]
244 + if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
245 then
216 - curl -s -o /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
246 + curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
247 ret=$?
248 fi
249
220 - if [ $ret -eq 0 -a -s /etc/netdata/netdata.conf.new ]
250 + if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
251 then
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"
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"
254
225 - chown "${NETDATA_USER}" /etc/netdata/netdata.conf
226 - chmod 0664 /etc/netdata/netdata.conf
255 + chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
256 + chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
257 else
258 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
259 + [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
260 fi
261 fi
262
@@ -245,7 +275,7 @@ To stop netdata, just kill it, with:
275
276 To start it, just run it:
277
248 - netdata
278 + ${NETDATA_PREFIX}/usr/sbin/netdata
279
280 Enjoy!
281