Fixes support for read-only /lib on SystemD systems like CoreOS in kickstart static64 (#7726)
* Fix formatting of functions.sh and errors found by shellcheck * Added support for other SystemD systems where /lib is read-only (e.g: CoreOS) * Fix minor typo(s)/grammar with safe_256sum() function * Fix shellcheck warnings in safe_256sum() function * Update the md5sum of the kickstart-static64.sh script in our docs to match
James Mills committed
Jan 17, 2020 at 01:12 UTC
c7e13846a87054d1e6e412d8edbc25b9dcbc684f
3 files changed
+634
-632
packaging/installer/README.md
+1
-1
@@ -116,7 +116,7 @@ This script installs Netdata at `/opt/netdata`.
116
Verify the integrity of the script with this:
117
118
```bash
119
-[ "9e0901736a8ed5ebcc84bc1c2c7b5db9" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
119
+[ "986e7756219717b075675ebe9b812916" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
120
```
121
122
*It should print `OK, VALID` if the script is the one we ship.*
packaging/installer/functions.sh
+629
-627
@@ -1,4 +1,5 @@
1
-# no shebang necessary - this is a library to be sourced
1
+#!/bin/bash
2
+
3
# SPDX-License-Identifier: GPL-3.0-or-later
4
# shellcheck disable=SC1091,SC1117,SC2002,SC2004,SC2034,SC2046,SC2059,SC2086,SC2129,SC2148,SC2154,SC2155,SC2162,SC2166,SC2181,SC2193
5
@@ -8,97 +9,97 @@
9
# -----------------------------------------------------------------------------
10
11
setup_terminal() {
11
- TPUT_RESET=""
12
- TPUT_BLACK=""
13
- TPUT_RED=""
14
- TPUT_GREEN=""
15
- TPUT_YELLOW=""
16
- TPUT_BLUE=""
17
- TPUT_PURPLE=""
18
- TPUT_CYAN=""
19
- TPUT_WHITE=""
20
- TPUT_BGBLACK=""
21
- TPUT_BGRED=""
22
- TPUT_BGGREEN=""
23
- TPUT_BGYELLOW=""
24
- TPUT_BGBLUE=""
25
- TPUT_BGPURPLE=""
26
- TPUT_BGCYAN=""
27
- TPUT_BGWHITE=""
28
- TPUT_BOLD=""
29
- TPUT_DIM=""
30
- TPUT_UNDERLINED=""
31
- TPUT_BLINK=""
32
- TPUT_INVERTED=""
33
- TPUT_STANDOUT=""
34
- TPUT_BELL=""
35
- TPUT_CLEAR=""
36
-
37
- # Is stderr on the terminal? If not, then fail
38
- test -t 2 || return 1
39
-
40
- if command -v tput 1>/dev/null 2>&1; then
41
- if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
42
- # Enable colors
43
- TPUT_RESET="$(tput sgr 0)"
44
- TPUT_BLACK="$(tput setaf 0)"
45
- TPUT_RED="$(tput setaf 1)"
46
- TPUT_GREEN="$(tput setaf 2)"
47
- TPUT_YELLOW="$(tput setaf 3)"
48
- TPUT_BLUE="$(tput setaf 4)"
49
- TPUT_PURPLE="$(tput setaf 5)"
50
- TPUT_CYAN="$(tput setaf 6)"
51
- TPUT_WHITE="$(tput setaf 7)"
52
- TPUT_BGBLACK="$(tput setab 0)"
53
- TPUT_BGRED="$(tput setab 1)"
54
- TPUT_BGGREEN="$(tput setab 2)"
55
- TPUT_BGYELLOW="$(tput setab 3)"
56
- TPUT_BGBLUE="$(tput setab 4)"
57
- TPUT_BGPURPLE="$(tput setab 5)"
58
- TPUT_BGCYAN="$(tput setab 6)"
59
- TPUT_BGWHITE="$(tput setab 7)"
60
- TPUT_BOLD="$(tput bold)"
61
- TPUT_DIM="$(tput dim)"
62
- TPUT_UNDERLINED="$(tput smul)"
63
- TPUT_BLINK="$(tput blink)"
64
- TPUT_INVERTED="$(tput rev)"
65
- TPUT_STANDOUT="$(tput smso)"
66
- TPUT_BELL="$(tput bel)"
67
- TPUT_CLEAR="$(tput clear)"
68
- fi
69
- fi
70
-
71
- return 0
12
+ TPUT_RESET=""
13
+ TPUT_BLACK=""
14
+ TPUT_RED=""
15
+ TPUT_GREEN=""
16
+ TPUT_YELLOW=""
17
+ TPUT_BLUE=""
18
+ TPUT_PURPLE=""
19
+ TPUT_CYAN=""
20
+ TPUT_WHITE=""
21
+ TPUT_BGBLACK=""
22
+ TPUT_BGRED=""
23
+ TPUT_BGGREEN=""
24
+ TPUT_BGYELLOW=""
25
+ TPUT_BGBLUE=""
26
+ TPUT_BGPURPLE=""
27
+ TPUT_BGCYAN=""
28
+ TPUT_BGWHITE=""
29
+ TPUT_BOLD=""
30
+ TPUT_DIM=""
31
+ TPUT_UNDERLINED=""
32
+ TPUT_BLINK=""
33
+ TPUT_INVERTED=""
34
+ TPUT_STANDOUT=""
35
+ TPUT_BELL=""
36
+ TPUT_CLEAR=""
37
+
38
+ # Is stderr on the terminal? If not, then fail
39
+ test -t 2 || return 1
40
+
41
+ if command -v tput 1>/dev/null 2>&1; then
42
+ if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
43
+ # Enable colors
44
+ TPUT_RESET="$(tput sgr 0)"
45
+ TPUT_BLACK="$(tput setaf 0)"
46
+ TPUT_RED="$(tput setaf 1)"
47
+ TPUT_GREEN="$(tput setaf 2)"
48
+ TPUT_YELLOW="$(tput setaf 3)"
49
+ TPUT_BLUE="$(tput setaf 4)"
50
+ TPUT_PURPLE="$(tput setaf 5)"
51
+ TPUT_CYAN="$(tput setaf 6)"
52
+ TPUT_WHITE="$(tput setaf 7)"
53
+ TPUT_BGBLACK="$(tput setab 0)"
54
+ TPUT_BGRED="$(tput setab 1)"
55
+ TPUT_BGGREEN="$(tput setab 2)"
56
+ TPUT_BGYELLOW="$(tput setab 3)"
57
+ TPUT_BGBLUE="$(tput setab 4)"
58
+ TPUT_BGPURPLE="$(tput setab 5)"
59
+ TPUT_BGCYAN="$(tput setab 6)"
60
+ TPUT_BGWHITE="$(tput setab 7)"
61
+ TPUT_BOLD="$(tput bold)"
62
+ TPUT_DIM="$(tput dim)"
63
+ TPUT_UNDERLINED="$(tput smul)"
64
+ TPUT_BLINK="$(tput blink)"
65
+ TPUT_INVERTED="$(tput rev)"
66
+ TPUT_STANDOUT="$(tput smso)"
67
+ TPUT_BELL="$(tput bel)"
68
+ TPUT_CLEAR="$(tput clear)"
69
+ fi
70
+ fi
71
+
72
+ return 0
73
}
74
setup_terminal || echo >/dev/null
75
76
progress() {
76
- echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
77
+ echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
78
}
79
80
# -----------------------------------------------------------------------------
81
82
netdata_banner() {
82
- local l1=" ^" \
83
- l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
84
- l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
85
- l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
86
- sp=" " \
87
- netdata="netdata" start end msg="${*}" chartcolor="${TPUT_DIM}"
83
+ local l1=" ^" \
84
+ l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
85
+ l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
86
+ l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
87
+ sp=" " \
88
+ netdata="netdata" start end msg="${*}" chartcolor="${TPUT_DIM}"
89
89
- [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$((${#netdata} - ${#msg}))}"
90
- [ ${#msg} -gt $((${#l2} - 20)) ] && msg="${msg:0:$((${#l2} - 23))}..."
90
+ [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$((${#netdata} - ${#msg}))}"
91
+ [ ${#msg} -gt $((${#l2} - 20)) ] && msg="${msg:0:$((${#l2} - 23))}..."
92
92
- start="$((${#l2} / 2 - 4))"
93
- [ $((start + ${#msg} + 4)) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
94
- end=$((start + ${#msg} + 4))
93
+ start="$((${#l2} / 2 - 4))"
94
+ [ $((start + ${#msg} + 4)) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
95
+ end=$((start + ${#msg} + 4))
96
96
- echo >&2
97
- echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
98
- echo >&2 "${chartcolor}${l2:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${TPUT_RESET}"
99
- echo >&2 "${chartcolor}${l3:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_CYAN}${msg}${TPUT_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${TPUT_RESET}"
100
- echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
101
- echo >&2
97
+ echo >&2
98
+ echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
99
+ echo >&2 "${chartcolor}${l2:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${TPUT_RESET}"
100
+ echo >&2 "${chartcolor}${l3:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_CYAN}${msg}${TPUT_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${TPUT_RESET}"
101
+ echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
102
+ echo >&2
103
}
104
105
# -----------------------------------------------------------------------------
@@ -109,225 +110,225 @@ rcservice_cmd="$(command -v rc-service 2>/dev/null)"
110
systemctl_cmd="$(command -v systemctl 2>/dev/null)"
111
service() {
112
112
- local cmd="${1}" action="${2}"
113
-
114
- if [ -n "${systemctl_cmd}" ]; then
115
- run "${systemctl_cmd}" "${action}" "${cmd}"
116
- return $?
117
- elif [ -n "${service_cmd}" ]; then
118
- run "${service_cmd}" "${cmd}" "${action}"
119
- return $?
120
- elif [ -n "${rcservice_cmd}" ]; then
121
- run "${rcservice_cmd}" "${cmd}" "${action}"
122
- return $?
123
- fi
124
- return 1
113
+ local cmd="${1}" action="${2}"
114
+
115
+ if [ -n "${systemctl_cmd}" ]; then
116
+ run "${systemctl_cmd}" "${action}" "${cmd}"
117
+ return $?
118
+ elif [ -n "${service_cmd}" ]; then
119
+ run "${service_cmd}" "${cmd}" "${action}"
120
+ return $?
121
+ elif [ -n "${rcservice_cmd}" ]; then
122
+ run "${rcservice_cmd}" "${cmd}" "${action}"
123
+ return $?
124
+ fi
125
+ return 1
126
}
127
128
# -----------------------------------------------------------------------------
129
# portable pidof
130
131
safe_pidof() {
131
- local pidof_cmd="$(command -v pidof 2>/dev/null)"
132
- if [ -n "${pidof_cmd}" ]; then
133
- ${pidof_cmd} "${@}"
134
- return $?
135
- else
136
- ps -acxo pid,comm |
137
- sed "s/^ *//g" |
138
- grep netdata |
139
- cut -d ' ' -f 1
140
- return $?
141
- fi
132
+ local pidof_cmd="$(command -v pidof 2>/dev/null)"
133
+ if [ -n "${pidof_cmd}" ]; then
134
+ ${pidof_cmd} "${@}"
135
+ return $?
136
+ else
137
+ ps -acxo pid,comm |
138
+ sed "s/^ *//g" |
139
+ grep netdata |
140
+ cut -d ' ' -f 1
141
+ return $?
142
+ fi
143
}
144
145
# -----------------------------------------------------------------------------
146
find_processors() {
146
- local cpus
147
- if [ -f "/proc/cpuinfo" ]; then
148
- # linux
149
- cpus=$(grep -c ^processor /proc/cpuinfo)
150
- else
151
- # freebsd
152
- cpus=$(sysctl hw.ncpu 2>/dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
153
- fi
154
- if [ -z "${cpus}" ] || [ $((cpus)) -lt 1 ]; then
155
- echo 1
156
- else
157
- echo "${cpus}"
158
- fi
147
+ local cpus
148
+ if [ -f "/proc/cpuinfo" ]; then
149
+ # linux
150
+ cpus=$(grep -c ^processor /proc/cpuinfo)
151
+ else
152
+ # freebsd
153
+ cpus=$(sysctl hw.ncpu 2>/dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
154
+ fi
155
+ if [ -z "${cpus}" ] || [ $((cpus)) -lt 1 ]; then
156
+ echo 1
157
+ else
158
+ echo "${cpus}"
159
+ fi
160
}
161
162
# -----------------------------------------------------------------------------
163
fatal() {
163
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
164
- exit 1
164
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
165
+ exit 1
166
}
167
168
run_ok() {
168
- printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
169
+ printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
170
}
171
172
run_failed() {
172
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
173
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
174
}
175
176
ESCAPED_PRINT_METHOD=
177
printf "%q " test >/dev/null 2>&1
178
[ $? -eq 0 ] && ESCAPED_PRINT_METHOD="printfq"
179
escaped_print() {
179
- if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
180
- printf "%q " "${@}"
181
- else
182
- printf "%s" "${*}"
183
- fi
184
- return 0
180
+ if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
181
+ printf "%q " "${@}"
182
+ else
183
+ printf "%s" "${*}"
184
+ fi
185
+ return 0
186
}
187
188
run_logfile="/dev/null"
189
run() {
189
- local user="${USER--}" dir="${PWD}" info info_console
190
-
191
- if [ "${UID}" = "0" ]; then
192
- info="[root ${dir}]# "
193
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
194
- else
195
- info="[${user} ${dir}]$ "
196
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
197
- fi
190
+ local user="${USER--}" dir="${PWD}" info info_console
191
+
192
+ if [ "${UID}" = "0" ]; then
193
+ info="[root ${dir}]# "
194
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
195
+ else
196
+ info="[${user} ${dir}]$ "
197
+ info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
198
+ fi
199
199
- printf >>"${run_logfile}" "${info}"
200
- escaped_print >>"${run_logfile}" "${@}"
201
- printf >>"${run_logfile}" " ... "
200
+ printf >>"${run_logfile}" "${info}"
201
+ escaped_print >>"${run_logfile}" "${@}"
202
+ printf >>"${run_logfile}" " ... "
203
203
- printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
204
- escaped_print >&2 "${@}"
205
- printf >&2 "${TPUT_RESET}\n"
204
+ printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
205
+ escaped_print >&2 "${@}"
206
+ printf >&2 "${TPUT_RESET}\n"
207
207
- "${@}"
208
+ "${@}"
209
209
- local ret=$?
210
- if [ ${ret} -ne 0 ]; then
211
- run_failed
212
- printf >>"${run_logfile}" "FAILED with exit code ${ret}\n"
213
- else
214
- run_ok
215
- printf >>"${run_logfile}" "OK\n"
216
- fi
210
+ local ret=$?
211
+ if [ ${ret} -ne 0 ]; then
212
+ run_failed
213
+ printf >>"${run_logfile}" "FAILED with exit code ${ret}\n"
214
+ else
215
+ run_ok
216
+ printf >>"${run_logfile}" "OK\n"
217
+ fi
218
218
- return ${ret}
219
+ return ${ret}
220
}
221
222
iscontainer() {
222
- # man systemd-detect-virt
223
- local cmd=$(command -v systemd-detect-virt 2>/dev/null)
224
- if [ -n "${cmd}" ] && [ -x "${cmd}" ]; then
225
- "${cmd}" --container >/dev/null 2>&1 && return 0
226
- fi
227
-
228
- # /proc/1/sched exposes the host's pid of our init !
229
- # http://stackoverflow.com/a/37016302
230
- local pid=$(cat /proc/1/sched 2>/dev/null | head -n 1 | {
231
- IFS='(),#:' read name pid th threads
232
- echo "$pid"
233
- })
234
- if [ -n "${pid}" ]; then
235
- pid=$(( pid + 0 ))
236
- [ ${pid} -gt 1 ] && return 0
237
- fi
238
-
239
- # lxc sets environment variable 'container'
240
- [ -n "${container}" ] && return 0
241
-
242
- # docker creates /.dockerenv
243
- # http://stackoverflow.com/a/25518345
244
- [ -f "/.dockerenv" ] && return 0
245
-
246
- # ubuntu and debian supply /bin/running-in-container
247
- # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
248
- if [ -x "/bin/running-in-container" ]; then
249
- "/bin/running-in-container" >/dev/null 2>&1 && return 0
250
- fi
251
-
252
- return 1
223
+ # man systemd-detect-virt
224
+ local cmd=$(command -v systemd-detect-virt 2>/dev/null)
225
+ if [ -n "${cmd}" ] && [ -x "${cmd}" ]; then
226
+ "${cmd}" --container >/dev/null 2>&1 && return 0
227
+ fi
228
+
229
+ # /proc/1/sched exposes the host's pid of our init !
230
+ # http://stackoverflow.com/a/37016302
231
+ local pid=$(cat /proc/1/sched 2>/dev/null | head -n 1 | {
232
+ IFS='(),#:' read name pid th threads
233
+ echo "$pid"
234
+ })
235
+ if [ -n "${pid}" ]; then
236
+ pid=$((pid + 0))
237
+ [ ${pid} -gt 1 ] && return 0
238
+ fi
239
+
240
+ # lxc sets environment variable 'container'
241
+ [ -n "${container}" ] && return 0
242
+
243
+ # docker creates /.dockerenv
244
+ # http://stackoverflow.com/a/25518345
245
+ [ -f "/.dockerenv" ] && return 0
246
+
247
+ # ubuntu and debian supply /bin/running-in-container
248
+ # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
249
+ if [ -x "/bin/running-in-container" ]; then
250
+ "/bin/running-in-container" >/dev/null 2>&1 && return 0
251
+ fi
252
+
253
+ return 1
254
}
255
256
issystemd() {
256
- local pids p myns ns systemctl
257
+ local pids p myns ns systemctl
258
258
- # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
259
- [ ! -d /lib/systemd/system -a ! -d /usr/lib/systemd/system ] && return 1
259
+ # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
260
+ [ ! -d /lib/systemd/system -a ! -d /usr/lib/systemd/system ] && return 1
261
261
- # if there is no systemctl command, it is not systemd
262
- # shellcheck disable=SC2230
263
- systemctl=$(command -v systemctl 2>/dev/null)
264
- [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
262
+ # if there is no systemctl command, it is not systemd
263
+ # shellcheck disable=SC2230
264
+ systemctl=$(command -v systemctl 2>/dev/null)
265
+ [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
266
266
- # if pid 1 is systemd, it is systemd
267
- [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
267
+ # if pid 1 is systemd, it is systemd
268
+ [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
269
269
- # if systemd is not running, it is not systemd
270
- pids=$(safe_pidof systemd 2>/dev/null)
271
- [ -z "${pids}" ] && return 1
270
+ # if systemd is not running, it is not systemd
271
+ pids=$(safe_pidof systemd 2>/dev/null)
272
+ [ -z "${pids}" ] && return 1
273
273
- # check if the running systemd processes are not in our namespace
274
- myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
275
- for p in ${pids}; do
276
- ns="$(readlink "/proc/${p}/ns/pid" 2>/dev/null)"
274
+ # check if the running systemd processes are not in our namespace
275
+ myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
276
+ for p in ${pids}; do
277
+ ns="$(readlink "/proc/${p}/ns/pid" 2>/dev/null)"
278
278
- # if pid of systemd is in our namespace, it is systemd
279
- [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
280
- done
279
+ # if pid of systemd is in our namespace, it is systemd
280
+ [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
281
+ done
282
282
- # else, it is not systemd
283
- return 1
283
+ # else, it is not systemd
284
+ return 1
285
}
286
287
install_non_systemd_init() {
287
- [ "${UID}" != 0 ] && return 1
288
-
289
- local key="unknown"
290
- if [ -f /etc/os-release ]; then
291
- source /etc/os-release || return 1
292
- key="${ID}-${VERSION_ID}"
293
-
294
- elif [ -f /etc/redhat-release ]; then
295
- key=$(</etc/redhat-release)
296
- fi
297
-
298
- if [ -d /etc/init.d ] && [ ! -f /etc/init.d/netdata ]; then
299
- if [[ ${key} =~ ^(gentoo|alpine).* ]]; then
300
- echo >&2 "Installing OpenRC init file..."
301
- run cp system/netdata-openrc /etc/init.d/netdata &&
302
- run chmod 755 /etc/init.d/netdata &&
303
- run rc-update add netdata default &&
304
- return 0
305
-
306
- elif [[ "${key}" =~ ^devuan* ]] || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
307
- echo >&2 "Installing LSB init file..."
308
- run cp system/netdata-lsb /etc/init.d/netdata &&
309
- run chmod 755 /etc/init.d/netdata &&
310
- run update-rc.d netdata defaults &&
311
- run update-rc.d netdata enable &&
312
- return 0
313
- elif [[ ${key} =~ ^(amzn-201[5678]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).* ]]; then
314
- echo >&2 "Installing init.d file..."
315
- run cp system/netdata-init-d /etc/init.d/netdata &&
316
- run chmod 755 /etc/init.d/netdata &&
317
- run chkconfig netdata on &&
318
- return 0
319
- else
320
- echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
321
- return 1
322
- fi
323
- elif [ -f /etc/init.d/netdata ]; then
324
- echo >&2 "file '/etc/init.d/netdata' already exists."
325
- return 0
326
- else
327
- echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
328
- fi
329
-
330
- return 1
288
+ [ "${UID}" != 0 ] && return 1
289
+
290
+ local key="unknown"
291
+ if [ -f /etc/os-release ]; then
292
+ source /etc/os-release || return 1
293
+ key="${ID}-${VERSION_ID}"
294
+
295
+ elif [ -f /etc/redhat-release ]; then
296
+ key=$(</etc/redhat-release)
297
+ fi
298
+
299
+ if [ -d /etc/init.d ] && [ ! -f /etc/init.d/netdata ]; then
300
+ if [[ ${key} =~ ^(gentoo|alpine).* ]]; then
301
+ echo >&2 "Installing OpenRC init file..."
302
+ run cp system/netdata-openrc /etc/init.d/netdata &&
303
+ run chmod 755 /etc/init.d/netdata &&
304
+ run rc-update add netdata default &&
305
+ return 0
306
+
307
+ elif [[ ${key} =~ ^devuan* ]] || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
308
+ echo >&2 "Installing LSB init file..."
309
+ run cp system/netdata-lsb /etc/init.d/netdata &&
310
+ run chmod 755 /etc/init.d/netdata &&
311
+ run update-rc.d netdata defaults &&
312
+ run update-rc.d netdata enable &&
313
+ return 0
314
+ elif [[ ${key} =~ ^(amzn-201[5678]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).* ]]; then
315
+ echo >&2 "Installing init.d file..."
316
+ run cp system/netdata-init-d /etc/init.d/netdata &&
317
+ run chmod 755 /etc/init.d/netdata &&
318
+ run chkconfig netdata on &&
319
+ return 0
320
+ else
321
+ echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
322
+ return 1
323
+ fi
324
+ elif [ -f /etc/init.d/netdata ]; then
325
+ echo >&2 "file '/etc/init.d/netdata' already exists."
326
+ return 0
327
+ else
328
+ echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
329
+ fi
330
+
331
+ return 1
332
}
333
334
NETDATA_START_CMD="netdata"
@@ -336,513 +337,514 @@ NETDATA_INSTALLER_START_CMD=""
337
NETDATA_INSTALLER_STOP_CMD="${NETDATA_STOP_CMD}"
338
339
install_netdata_service() {
339
- local uname="$(uname 2>/dev/null)"
340
-
341
- if [ "${UID}" -eq 0 ]; then
342
- if [ "${uname}" = "Darwin" ]; then
343
-
344
- if [ -f "/Library/LaunchDaemons/com.github.netdata.plist" ]; then
345
- echo >&2 "file '/Library/LaunchDaemons/com.github.netdata.plist' already exists."
346
- return 0
347
- else
348
- echo >&2 "Installing MacOS X plist file..."
349
- run cp system/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist &&
350
- run launchctl load /Library/LaunchDaemons/com.github.netdata.plist &&
351
- return 0
352
- fi
353
-
354
- elif [ "${uname}" = "FreeBSD" ]; then
355
-
356
- run cp system/netdata-freebsd /etc/rc.d/netdata && NETDATA_START_CMD="service netdata start" &&
357
- NETDATA_STOP_CMD="service netdata stop" &&
358
- NETDATA_INSTALLER_START_CMD="service netdata onestart" &&
359
- NETDATA_INSTALLER_STOP_CMD="${NETDATA_STOP_CMD}"
360
- myret=$?
361
-
362
- echo >&2 "Note: To explicitly enable netdata automatic start, set 'netdata_enable' to 'YES' in /etc/rc.conf"
363
- echo >&2 ""
364
-
365
- return ${myret}
366
-
367
- elif issystemd; then
368
- # systemd is running on this system
369
- NETDATA_START_CMD="systemctl start netdata"
370
- NETDATA_STOP_CMD="systemctl stop netdata"
371
- NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
372
- NETDATA_INSTALLER_STOP_CMD="${NETDATA_STOP_CMD}"
373
-
374
- SYSTEMD_DIRECTORY=""
375
-
376
- if [ -d "/lib/systemd/system" ]; then
377
- SYSTEMD_DIRECTORY="/lib/systemd/system"
378
- elif [ -d "/usr/lib/systemd/system" ]; then
379
- SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
380
- fi
381
-
382
- if [ "${SYSTEMD_DIRECTORY}x" != "x" ]; then
383
- ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="run systemctl enable netdata"
384
- IS_NETDATA_ENABLED="$(systemctl is-enabled netdata 2> /dev/null || echo "Netdata not there")"
385
- if [ "${IS_NETDATA_ENABLED}" == "disabled" ]; then
386
- echo >&2 "Netdata was there and disabled, make sure we don't re-enable it ourselves"
387
- ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="true"
388
- fi
389
-
390
- echo >&2 "Installing systemd service..."
391
- run cp system/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" &&
392
- run systemctl daemon-reload &&
393
- ${ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED} &&
394
- return 0
395
- else
396
- echo >&2 "no systemd directory; cannot install netdata.service"
397
- fi
398
- else
399
- install_non_systemd_init
400
- local ret=$?
401
-
402
- if [ ${ret} -eq 0 ]; then
403
- if [ -n "${service_cmd}" ]; then
404
- NETDATA_START_CMD="service netdata start"
405
- NETDATA_STOP_CMD="service netdata stop"
406
- elif [ -n "${rcservice_cmd}" ]; then
407
- NETDATA_START_CMD="rc-service netdata start"
408
- NETDATA_STOP_CMD="rc-service netdata stop"
409
- fi
410
- NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
411
- NETDATA_INSTALLER_STOP_CMD="${NETDATA_STOP_CMD}"
412
- fi
413
-
414
- return ${ret}
415
- fi
416
- fi
417
-
418
- return 1
340
+ local uname="$(uname 2>/dev/null)"
341
+
342
+ if [ "${UID}" -eq 0 ]; then
343
+ if [ "${uname}" = "Darwin" ]; then
344
+
345
+ if [ -f "/Library/LaunchDaemons/com.github.netdata.plist" ]; then
346
+ echo >&2 "file '/Library/LaunchDaemons/com.github.netdata.plist' already exists."
347
+ return 0
348
+ else
349
+ echo >&2 "Installing MacOS X plist file..."
350
+ run cp system/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist &&
351
+ run launchctl load /Library/LaunchDaemons/com.github.netdata.plist &&
352
+ return 0
353
+ fi
354
+
355
+ elif [ "${uname}" = "FreeBSD" ]; then
356
+
357
+ run cp system/netdata-freebsd /etc/rc.d/netdata && NETDATA_START_CMD="service netdata start" &&
358
+ NETDATA_STOP_CMD="service netdata stop" &&
359
+ NETDATA_INSTALLER_START_CMD="service netdata onestart" &&
360
+ NETDATA_INSTALLER_STOP_CMD="${NETDATA_STOP_CMD}"
361
+ myret=$?
362
+
363
+ echo >&2 "Note: To explicitly enable netdata automatic start, set 'netdata_enable' to 'YES' in /etc/rc.conf"
364
+ echo >&2 ""
365
+
366
+ return ${myret}
367
+
368
+ elif issystemd; then
369
+ # systemd is running on this system
370
+ NETDATA_START_CMD="systemctl start netdata"
371
+ NETDATA_STOP_CMD="systemctl stop netdata"
372
+ NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
373
+ NETDATA_INSTALLER_STOP_CMD="${NETDATA_STOP_CMD}"
374
+
375
+ SYSTEMD_DIRECTORY=""
376
+
377
+ if [ -w "/lib/systemd/system" ]; then
378
+ SYSTEMD_DIRECTORY="/lib/systemd/system"
379
+ elif [ -w "/usr/lib/systemd/system" ]; then
380
+ SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
381
+ elif [ -w "/etc/systemd/system" ]; then
382
+ SYSTEM_DIRECTORY="/etc/systemd/system"
383
+ fi
384
+
385
+ if [ "${SYSTEMD_DIRECTORY}x" != "x" ]; then
386
+ ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="run systemctl enable netdata"
387
+ IS_NETDATA_ENABLED="$(systemctl is-enabled netdata 2>/dev/null || echo "Netdata not there")"
388
+ if [ "${IS_NETDATA_ENABLED}" == "disabled" ]; then
389
+ echo >&2 "Netdata was there and disabled, make sure we don't re-enable it ourselves"
390
+ ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="true"
391
+ fi
392
+
393
+ echo >&2 "Installing systemd service..."
394
+ run cp system/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" &&
395
+ run systemctl daemon-reload &&
396
+ ${ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED} &&
397
+ return 0
398
+ else
399
+ echo >&2 "no systemd directory; cannot install netdata.service"
400
+ fi
401
+ else
402
+ install_non_systemd_init
403
+ local ret=$?
404
+
405
+ if [ ${ret} -eq 0 ]; then
406
+ if [ -n "${service_cmd}" ]; then
407
+ NETDATA_START_CMD="service netdata start"
408
+ NETDATA_STOP_CMD="service netdata stop"
409
+ elif [ -n "${rcservice_cmd}" ]; then
410
+ NETDATA_START_CMD="rc-service netdata start"
411
+ NETDATA_STOP_CMD="rc-service netdata stop"
412
+ fi
413
+ NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
414
+ NETDATA_INSTALLER_STOP_CMD="${NETDATA_STOP_CMD}"
415
+ fi
416
+
417
+ return ${ret}
418
+ fi
419
+ fi
420
+
421
+ return 1
422
}
423
424
# -----------------------------------------------------------------------------
425
# stop netdata
426
427
pidisnetdata() {
425
- if [ -d /proc/self ]; then
426
- [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
427
- [ "$(cut -d '(' -f 2 "/proc/$1/stat" | cut -d ')' -f 1)" = "netdata" ] && return 0
428
- return 1
429
- fi
430
- return 0
428
+ if [ -d /proc/self ]; then
429
+ [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
430
+ [ "$(cut -d '(' -f 2 "/proc/$1/stat" | cut -d ')' -f 1)" = "netdata" ] && return 0
431
+ return 1
432
+ fi
433
+ return 0
434
}
435
436
stop_netdata_on_pid() {
434
- local pid="${1}" ret=0 count=0
437
+ local pid="${1}" ret=0 count=0
438
436
- pidisnetdata "${pid}" || return 0
439
+ pidisnetdata "${pid}" || return 0
440
438
- printf >&2 "Stopping netdata on pid %s ..." "${pid}"
439
- while [ -n "$pid" ] && [ ${ret} -eq 0 ]; do
440
- if [ ${count} -gt 24 ]; then
441
- echo >&2 "Cannot stop the running netdata on pid ${pid}."
442
- return 1
443
- fi
441
+ printf >&2 "Stopping netdata on pid %s ..." "${pid}"
442
+ while [ -n "$pid" ] && [ ${ret} -eq 0 ]; do
443
+ if [ ${count} -gt 24 ]; then
444
+ echo >&2 "Cannot stop the running netdata on pid ${pid}."
445
+ return 1
446
+ fi
447
445
- count=$((count + 1))
448
+ count=$((count + 1))
449
447
- pidisnetdata "${pid}" || ret=1
448
- if [ ${ret} -eq 1 ] ; then
449
- break
450
- fi
450
+ pidisnetdata "${pid}" || ret=1
451
+ if [ ${ret} -eq 1 ]; then
452
+ break
453
+ fi
454
452
- if [ ${count} -lt 12 ] ; then
453
- run kill "${pid}" 2>/dev/null
454
- ret=$?
455
- else
456
- run kill -9 "${pid}" 2>/dev/null
457
- ret=$?
458
- fi
455
+ if [ ${count} -lt 12 ]; then
456
+ run kill "${pid}" 2>/dev/null
457
+ ret=$?
458
+ else
459
+ run kill -9 "${pid}" 2>/dev/null
460
+ ret=$?
461
+ fi
462
460
- test ${ret} -eq 0 && printf >&2 "." && sleep 5
463
+ test ${ret} -eq 0 && printf >&2 "." && sleep 5
464
462
- done
465
+ done
466
464
- echo >&2
465
- if [ ${ret} -eq 0 ]; then
466
- echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
467
- return 1
468
- fi
467
+ echo >&2
468
+ if [ ${ret} -eq 0 ]; then
469
+ echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
470
+ return 1
471
+ fi
472
470
- echo >&2 "netdata on pid ${pid} stopped."
471
- return 0
473
+ echo >&2 "netdata on pid ${pid} stopped."
474
+ return 0
475
}
476
477
netdata_pids() {
475
- local p myns ns
478
+ local p myns ns
479
477
- myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
480
+ myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
481
479
- for p in \
480
- $(cat /var/run/netdata.pid 2>/dev/null) \
481
- $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
482
- $(safe_pidof netdata 2>/dev/null); do
483
- ns="$(readlink "/proc/${p}/ns/pid" 2>/dev/null)"
482
+ for p in \
483
+ $(cat /var/run/netdata.pid 2>/dev/null) \
484
+ $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
485
+ $(safe_pidof netdata 2>/dev/null); do
486
+ ns="$(readlink "/proc/${p}/ns/pid" 2>/dev/null)"
487
485
- if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
486
- pidisnetdata "${p}" && echo "${p}"
487
- fi
488
- done
488
+ if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
489
+ pidisnetdata "${p}" && echo "${p}"
490
+ fi
491
+ done
492
}
493
494
stop_all_netdata() {
492
- local p
495
+ local p
496
494
- if [ -n "$(netdata_pids)" -a -n "$(builtin type -P netdatacli)" ] ; then
495
- netdatacli shutdown-agent
496
- sleep 20
497
- fi
497
+ if [ -n "$(netdata_pids)" -a -n "$(builtin type -P netdatacli)" ]; then
498
+ netdatacli shutdown-agent
499
+ sleep 20
500
+ fi
501
499
- for p in $(netdata_pids); do
500
- # shellcheck disable=SC2086
501
- stop_netdata_on_pid ${p}
502
- done
502
+ for p in $(netdata_pids); do
503
+ # shellcheck disable=SC2086
504
+ stop_netdata_on_pid ${p}
505
+ done
506
}
507
508
# -----------------------------------------------------------------------------
509
# restart netdata
510
511
restart_netdata() {
509
- local netdata="${1}"
510
- shift
512
+ local netdata="${1}"
513
+ shift
514
512
- local started=0
515
+ local started=0
516
514
- progress "Restarting netdata instance"
517
+ progress "Restarting netdata instance"
518
516
- if [ -z "${NETDATA_INSTALLER_START_CMD}" ] ; then
517
- NETDATA_INSTALLER_START_CMD="${netdata}"
518
- fi
519
+ if [ -z "${NETDATA_INSTALLER_START_CMD}" ]; then
520
+ NETDATA_INSTALLER_START_CMD="${netdata}"
521
+ fi
522
520
- if [ "${UID}" -eq 0 ]; then
521
- echo >&2
522
- echo >&2 "Stopping all netdata threads"
523
- run stop_all_netdata
523
+ if [ "${UID}" -eq 0 ]; then
524
+ echo >&2
525
+ echo >&2 "Stopping all netdata threads"
526
+ run stop_all_netdata
527
525
- echo >&2 "Starting netdata using command '${NETDATA_INSTALLER_START_CMD}'"
526
- run ${NETDATA_INSTALLER_START_CMD} && started=1
528
+ echo >&2 "Starting netdata using command '${NETDATA_INSTALLER_START_CMD}'"
529
+ run ${NETDATA_INSTALLER_START_CMD} && started=1
530
528
- if [ ${started} -eq 1 ] && [ -z "$(netdata_pids)" ]; then
529
- echo >&2 "Ooops! it seems netdata is not started."
530
- started=0
531
- fi
531
+ if [ ${started} -eq 1 ] && [ -z "$(netdata_pids)" ]; then
532
+ echo >&2 "Ooops! it seems netdata is not started."
533
+ started=0
534
+ fi
535
533
- if [ ${started} -eq 0 ]; then
534
- echo >&2 "Attempting another netdata start using command '${NETDATA_INSTALLER_START_CMD}'"
535
- run ${NETDATA_INSTALLER_START_CMD} && started=1
536
- fi
537
- fi
536
+ if [ ${started} -eq 0 ]; then
537
+ echo >&2 "Attempting another netdata start using command '${NETDATA_INSTALLER_START_CMD}'"
538
+ run ${NETDATA_INSTALLER_START_CMD} && started=1
539
+ fi
540
+ fi
541
539
- if [ ${started} -eq 1 ] && [ -z "$(netdata_pids)" ]; then
540
- echo >&2 "Hm... it seems netdata is still not started."
541
- started=0
542
- fi
542
+ if [ ${started} -eq 1 ] && [ -z "$(netdata_pids)" ]; then
543
+ echo >&2 "Hm... it seems netdata is still not started."
544
+ started=0
545
+ fi
546
544
- if [ ${started} -eq 0 ]; then
545
- # still not started... another forced attempt, just run the binary
546
- echo >&2 "Netdata service still not started, attempting another forced restart by running '${netdata} ${@}'"
547
- run stop_all_netdata
548
- run "${netdata}" "${@}"
549
- return $?
550
- fi
547
+ if [ ${started} -eq 0 ]; then
548
+ # still not started... another forced attempt, just run the binary
549
+ echo >&2 "Netdata service still not started, attempting another forced restart by running '${netdata} ${*}'"
550
+ run stop_all_netdata
551
+ run "${netdata}" "${@}"
552
+ return $?
553
+ fi
554
552
- return 0
555
+ return 0
556
}
557
558
# -----------------------------------------------------------------------------
559
# install netdata logrotate
560
561
install_netdata_logrotate() {
559
- if [ "${UID}" -eq 0 ]; then
560
- if [ -d /etc/logrotate.d ]; then
561
- if [ ! -f /etc/logrotate.d/netdata ]; then
562
- run cp system/netdata.logrotate /etc/logrotate.d/netdata
563
- fi
564
-
565
- if [ -f /etc/logrotate.d/netdata ]; then
566
- run chmod 644 /etc/logrotate.d/netdata
567
- fi
568
-
569
- return 0
570
- fi
571
- fi
562
+ if [ "${UID}" -eq 0 ]; then
563
+ if [ -d /etc/logrotate.d ]; then
564
+ if [ ! -f /etc/logrotate.d/netdata ]; then
565
+ run cp system/netdata.logrotate /etc/logrotate.d/netdata
566
+ fi
567
+
568
+ if [ -f /etc/logrotate.d/netdata ]; then
569
+ run chmod 644 /etc/logrotate.d/netdata
570
+ fi
571
+
572
+ return 0
573
+ fi
574
+ fi
575
573
- return 1
576
+ return 1
577
}
578
579
# -----------------------------------------------------------------------------
580
# create netdata.conf
581
582
create_netdata_conf() {
580
- local path="${1}" url="${2}"
581
-
582
- if [ -s "${path}" ]; then
583
- return 0
584
- fi
585
-
586
- if [ -n "$url" ]; then
587
- echo >&2 "Downloading default configuration from netdata..."
588
- sleep 5
589
-
590
- # remove a possibly obsolete configuration file
591
- [ -f "${path}.new" ] && rm "${path}.new"
583
+ local path="${1}" url="${2}"
584
593
- # disable a proxy to get data from the local netdata
594
- export http_proxy=
595
- export https_proxy=
596
-
597
- if command -v curl 1>/dev/null 2>&1; then
598
- run curl -sSL --connect-timeout 10 --retry 3 "${url}" >"${path}.new"
599
- elif command -v wget 1>/dev/null 2>&1; then
600
- run wget -T 15 -O - "${url}" >"${path}.new"
601
- fi
585
+ if [ -s "${path}" ]; then
586
+ return 0
587
+ fi
588
603
- if [ -s "${path}.new" ]; then
604
- run mv "${path}.new" "${path}"
605
- run_ok "New configuration saved for you to edit at ${path}"
606
- else
607
- [ -f "${path}.new" ] && rm "${path}.new"
608
- run_failed "Cannnot download configuration from netdata daemon using url '${url}'"
609
- url=''
610
- fi
611
- fi
589
+ if [ -n "$url" ]; then
590
+ echo >&2 "Downloading default configuration from netdata..."
591
+ sleep 5
592
+
593
+ # remove a possibly obsolete configuration file
594
+ [ -f "${path}.new" ] && rm "${path}.new"
595
+
596
+ # disable a proxy to get data from the local netdata
597
+ export http_proxy=
598
+ export https_proxy=
599
+
600
+ if command -v curl 1>/dev/null 2>&1; then
601
+ run curl -sSL --connect-timeout 10 --retry 3 "${url}" >"${path}.new"
602
+ elif command -v wget 1>/dev/null 2>&1; then
603
+ run wget -T 15 -O - "${url}" >"${path}.new"
604
+ fi
605
+
606
+ if [ -s "${path}.new" ]; then
607
+ run mv "${path}.new" "${path}"
608
+ run_ok "New configuration saved for you to edit at ${path}"
609
+ else
610
+ [ -f "${path}.new" ] && rm "${path}.new"
611
+ run_failed "Cannnot download configuration from netdata daemon using url '${url}'"
612
+ url=''
613
+ fi
614
+ fi
615
613
- if [ -z "$url" ]; then
614
- echo "# netdata can generate its own config which is available at 'http://<netdata_ip>/netdata.conf'" >"${path}"
615
- echo "# You can download it with command like: 'wget -O ${path} http://localhost:19999/netdata.conf'" >>"${path}"
616
- fi
616
+ if [ -z "$url" ]; then
617
+ echo "# netdata can generate its own config which is available at 'http://<netdata_ip>/netdata.conf'" >"${path}"
618
+ echo "# You can download it with command like: 'wget -O ${path} http://localhost:19999/netdata.conf'" >>"${path}"
619
+ fi
620
621
}
622
623
portable_add_user() {
621
- local username="${1}" homedir="${2}"
624
+ local username="${1}" homedir="${2}"
625
623
- [ -z "${homedir}" ] && homedir="/tmp"
626
+ [ -z "${homedir}" ] && homedir="/tmp"
627
628
# Check if user exists
626
- if cut -d ':' -f 1 </etc/passwd | grep "^${username}$" 1>/dev/null 2>&1; then
629
+ if cut -d ':' -f 1 </etc/passwd | grep "^${username}$" 1>/dev/null 2>&1; then
630
echo >&2 "User '${username}' already exists."
631
return 0
632
fi
633
631
- echo >&2 "Adding ${username} user account with home ${homedir} ..."
634
+ echo >&2 "Adding ${username} user account with home ${homedir} ..."
635
633
- # shellcheck disable=SC2230
634
- local nologin="$(command -v nologin || echo '/bin/false')"
636
+ # shellcheck disable=SC2230
637
+ local nologin="$(command -v nologin || echo '/bin/false')"
638
636
- # Linux
637
- if command -v useradd 1>/dev/null 2>&1; then
638
- run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
639
- fi
639
+ # Linux
640
+ if command -v useradd 1>/dev/null 2>&1; then
641
+ run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
642
+ fi
643
641
- # FreeBSD
642
- if command -v pw 1>/dev/null 2>&1; then
643
- run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
644
- fi
644
+ # FreeBSD
645
+ if command -v pw 1>/dev/null 2>&1; then
646
+ run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
647
+ fi
648
646
- # BusyBox
647
- if command -v adduser 1>/dev/null 2>&1; then
648
- run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
649
- fi
649
+ # BusyBox
650
+ if command -v adduser 1>/dev/null 2>&1; then
651
+ run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
652
+ fi
653
651
- # mac OS
652
- if command -v sysadminctl 1> /dev/null 2>&1; then
653
- run sysadminctl -addUser ${username} && return 0
654
- fi
654
+ # mac OS
655
+ if command -v sysadminctl 1>/dev/null 2>&1; then
656
+ run sysadminctl -addUser ${username} && return 0
657
+ fi
658
656
- echo >&2 "Failed to add ${username} user account !"
659
+ echo >&2 "Failed to add ${username} user account !"
660
658
- return 1
661
+ return 1
662
}
663
664
portable_add_group() {
662
- local groupname="${1}"
665
+ local groupname="${1}"
666
664
- # Check if group exist
665
- if cut -d ':' -f 1 </etc/group | grep "^${groupname}$" 1>/dev/null 2>&1; then
666
- echo >&2 "Group '${groupname}' already exists."
667
- return 0
668
- fi
667
+ # Check if group exist
668
+ if cut -d ':' -f 1 </etc/group | grep "^${groupname}$" 1>/dev/null 2>&1; then
669
+ echo >&2 "Group '${groupname}' already exists."
670
+ return 0
671
+ fi
672
670
- echo >&2 "Adding ${groupname} user group ..."
673
+ echo >&2 "Adding ${groupname} user group ..."
674
672
- # Linux
673
- if command -v groupadd 1>/dev/null 2>&1; then
674
- run groupadd -r "${groupname}" && return 0
675
- fi
675
+ # Linux
676
+ if command -v groupadd 1>/dev/null 2>&1; then
677
+ run groupadd -r "${groupname}" && return 0
678
+ fi
679
677
- # FreeBSD
678
- if command -v pw 1>/dev/null 2>&1; then
679
- run pw groupadd "${groupname}" && return 0
680
- fi
680
+ # FreeBSD
681
+ if command -v pw 1>/dev/null 2>&1; then
682
+ run pw groupadd "${groupname}" && return 0
683
+ fi
684
682
- # BusyBox
683
- if command -v addgroup 1>/dev/null 2>&1; then
684
- run addgroup "${groupname}" && return 0
685
- fi
685
+ # BusyBox
686
+ if command -v addgroup 1>/dev/null 2>&1; then
687
+ run addgroup "${groupname}" && return 0
688
+ fi
689
687
- # mac OS
688
- if command -v dseditgroup 1> /dev/null 2>&1; then
689
- dseditgroup -o create "${groupname}" && return 0
690
- fi
690
+ # mac OS
691
+ if command -v dseditgroup 1>/dev/null 2>&1; then
692
+ dseditgroup -o create "${groupname}" && return 0
693
+ fi
694
692
- echo >&2 "Failed to add ${groupname} user group !"
693
- return 1
695
+ echo >&2 "Failed to add ${groupname} user group !"
696
+ return 1
697
}
698
699
portable_add_user_to_group() {
697
- local groupname="${1}" username="${2}"
698
-
699
- # Check if group exist
700
- if ! cut -d ':' -f 1 </etc/group | grep "^${groupname}$" >/dev/null 2>&1; then
701
- echo >&2 "Group '${groupname}' does not exist."
702
- return 1
703
- fi
704
-
705
- # Check if user is in group
706
- if [[ ",$(grep "^${groupname}:" </etc/group | cut -d ':' -f 4)," =~ ,${username}, ]]; then
707
- # username is already there
708
- echo >&2 "User '${username}' is already in group '${groupname}'."
709
- return 0
710
- else
711
- # username is not in group
712
- echo >&2 "Adding ${username} user to the ${groupname} group ..."
713
-
714
- # Linux
715
- if command -v usermod 1>/dev/null 2>&1; then
716
- run usermod -a -G "${groupname}" "${username}" && return 0
717
- fi
718
-
719
- # FreeBSD
720
- if command -v pw 1>/dev/null 2>&1; then
721
- run pw groupmod "${groupname}" -m "${username}" && return 0
722
- fi
723
-
724
- # BusyBox
725
- if command -v addgroup 1>/dev/null 2>&1; then
726
- run addgroup "${username}" "${groupname}" && return 0
727
- fi
728
-
729
- # mac OS
730
- if command -v dseditgroup 1> /dev/null 2>&1; then
731
- dseditgroup -u "${username}" "${groupname}" && return 0
732
- fi
733
- echo >&2 "Failed to add user ${username} to group ${groupname} !"
734
- return 1
735
- fi
736
-}
700
+ local groupname="${1}" username="${2}"
701
702
+ # Check if group exist
703
+ if ! cut -d ':' -f 1 </etc/group | grep "^${groupname}$" >/dev/null 2>&1; then
704
+ echo >&2 "Group '${groupname}' does not exist."
705
+ return 1
706
+ fi
707
+
708
+ # Check if user is in group
709
+ if [[ ",$(grep "^${groupname}:" </etc/group | cut -d ':' -f 4)," =~ ,${username}, ]]; then
710
+ # username is already there
711
+ echo >&2 "User '${username}' is already in group '${groupname}'."
712
+ return 0
713
+ else
714
+ # username is not in group
715
+ echo >&2 "Adding ${username} user to the ${groupname} group ..."
716
+
717
+ # Linux
718
+ if command -v usermod 1>/dev/null 2>&1; then
719
+ run usermod -a -G "${groupname}" "${username}" && return 0
720
+ fi
721
+
722
+ # FreeBSD
723
+ if command -v pw 1>/dev/null 2>&1; then
724
+ run pw groupmod "${groupname}" -m "${username}" && return 0
725
+ fi
726
+
727
+ # BusyBox
728
+ if command -v addgroup 1>/dev/null 2>&1; then
729
+ run addgroup "${username}" "${groupname}" && return 0
730
+ fi
731
+
732
+ # mac OS
733
+ if command -v dseditgroup 1>/dev/null 2>&1; then
734
+ dseditgroup -u "${username}" "${groupname}" && return 0
735
+ fi
736
+ echo >&2 "Failed to add user ${username} to group ${groupname} !"
737
+ return 1
738
+ fi
739
+}
740
741
safe_sha256sum() {
740
- # Within the contexct of the installer, we only use -c option that is common between the two commands
741
- # We will have to reconsider if we start non-common options
742
- if command -v sha256sum >/dev/null 2>&1; then
743
- sha256sum $@
744
- elif command -v shasum >/dev/null 2>&1; then
745
- shasum -a 256 $@
746
- else
747
- fatal "I could not find a suitable checksum binary to use"
748
- fi
742
+ # Within the contexct of the installer, we only use -c option that is common between the two commands
743
+ # We will have to reconsider if we start non-common options
744
+ if command -v sha256sum >/dev/null 2>&1; then
745
+ sha256sum "$@"
746
+ elif command -v shasum >/dev/null 2>&1; then
747
+ shasum -a 256 "$@"
748
+ else
749
+ fatal "I could not find a suitable checksum binary to use"
750
+ fi
751
}
752
753
_get_crondir() {
752
- if [ -d /etc/cron.daily ]; then
753
- echo /etc/cron.daily
754
- elif [ -d /etc/periodic/daily ]; then
755
- echo /etc/periodic/daily
756
- else
757
- echo >&2 "Cannot figure out the cron directory to handle netdata-updater.sh activation/deactivation"
758
- return 1
759
- fi
754
+ if [ -d /etc/cron.daily ]; then
755
+ echo /etc/cron.daily
756
+ elif [ -d /etc/periodic/daily ]; then
757
+ echo /etc/periodic/daily
758
+ else
759
+ echo >&2 "Cannot figure out the cron directory to handle netdata-updater.sh activation/deactivation"
760
+ return 1
761
+ fi
762
761
- return 0
763
+ return 0
764
}
765
766
_check_crondir_permissions() {
765
- if [ "${UID}" -ne "0" ]; then
766
- # We cant touch cron if we are not running as root
767
- echo >&2 "You need to run the installer as root for auto-updating via cron"
768
- return 1
769
- fi
767
+ if [ "${UID}" -ne "0" ]; then
768
+ # We cant touch cron if we are not running as root
769
+ echo >&2 "You need to run the installer as root for auto-updating via cron"
770
+ return 1
771
+ fi
772
771
- return 0
773
+ return 0
774
}
775
776
install_netdata_updater() {
775
- if [ "${INSTALLER_DIR}" ] && [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
776
- cat "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
777
- fi
777
+ if [ "${INSTALLER_DIR}" ] && [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
778
+ cat "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" >"${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
779
+ fi
780
779
- if [ "${NETDATA_SOURCE_DIR}" ] && [ -f "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" ]; then
780
- cat "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
781
- fi
781
+ if [ "${NETDATA_SOURCE_DIR}" ] && [ -f "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" ]; then
782
+ cat "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" >"${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
783
+ fi
784
783
- sed -e "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" -i "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
785
+ sed -e "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" -i "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
786
785
- chmod 0755 ${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh
786
- echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh${TPUT_RESET}"
787
- echo >&2
787
+ chmod 0755 ${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh
788
+ echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh${TPUT_RESET}"
789
+ echo >&2
790
789
- return 0
791
+ return 0
792
}
793
794
cleanup_old_netdata_updater() {
793
- if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-updater.sh ]; then
794
- echo >&2 "Removing updater from deprecated location"
795
- rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-updater.sh
796
- fi
795
+ if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-updater.sh ]; then
796
+ echo >&2 "Removing updater from deprecated location"
797
+ rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-updater.sh
798
+ fi
799
798
- crondir="$(_get_crondir)" || return 1
799
- _check_crondir_permissions "${crondir}" || return 1
800
+ crondir="$(_get_crondir)" || return 1
801
+ _check_crondir_permissions "${crondir}" || return 1
802
801
- if [ -f "${crondir}/netdata-updater.sh" ]; then
802
- echo >&2 "Removing incorrect netdata-updater filename in cron"
803
- rm -f "${crondir}/netdata-updater.sh"
804
- fi
803
+ if [ -f "${crondir}/netdata-updater.sh" ]; then
804
+ echo >&2 "Removing incorrect netdata-updater filename in cron"
805
+ rm -f "${crondir}/netdata-updater.sh"
806
+ fi
807
806
- return 0
808
+ return 0
809
}
810
811
enable_netdata_updater() {
810
- crondir="$(_get_crondir)" || return 1
811
- _check_crondir_permissions "${crondir}" || return 1
812
+ crondir="$(_get_crondir)" || return 1
813
+ _check_crondir_permissions "${crondir}" || return 1
814
813
- echo >&2 "Adding to cron"
815
+ echo >&2 "Adding to cron"
816
815
- rm -f "${crondir}/netdata-updater"
816
- ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "${crondir}/netdata-updater"
817
+ rm -f "${crondir}/netdata-updater"
818
+ ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "${crondir}/netdata-updater"
819
818
- echo >&2 "Auto-updating has been enabled. Updater script linked to: ${TPUT_RED}${TPUT_BOLD}${crondir}/netdata-update${TPUT_RESET}"
819
- echo >&2
820
- echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} works from cron. It will trigger an email from cron"
821
- echo >&2 "only if it fails (it should not print anything when it can update netdata).${TPUT_RESET}"
822
- echo >&2
820
+ echo >&2 "Auto-updating has been enabled. Updater script linked to: ${TPUT_RED}${TPUT_BOLD}${crondir}/netdata-update${TPUT_RESET}"
821
+ echo >&2
822
+ echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} works from cron. It will trigger an email from cron"
823
+ echo >&2 "only if it fails (it should not print anything when it can update netdata).${TPUT_RESET}"
824
+ echo >&2
825
824
- return 0
826
+ return 0
827
}
828
829
disable_netdata_updater() {
828
- crondir="$(_get_crondir)" || return 1
829
- _check_crondir_permissions "${crondir}" || return 1
830
-
831
- echo >&2 "You chose *NOT* to enable auto-update, removing any links to the updater from cron (it may have happened if you are reinstalling)"
832
- echo >&2
833
-
834
- if [ -f "${crondir}/netdata-updater" ]; then
835
- echo >&2 "Removing cron reference: ${crondir}/netdata-updater"
836
- echo >&2
837
- rm -f "${crondir}/netdata-updater"
838
- else
839
- echo >&2 "Did not find any cron entries to remove"
840
- echo >&2
841
- fi
830
+ crondir="$(_get_crondir)" || return 1
831
+ _check_crondir_permissions "${crondir}" || return 1
832
+
833
+ echo >&2 "You chose *NOT* to enable auto-update, removing any links to the updater from cron (it may have happened if you are reinstalling)"
834
+ echo >&2
835
+
836
+ if [ -f "${crondir}/netdata-updater" ]; then
837
+ echo >&2 "Removing cron reference: ${crondir}/netdata-updater"
838
+ echo >&2
839
+ rm -f "${crondir}/netdata-updater"
840
+ else
841
+ echo >&2 "Did not find any cron entries to remove"
842
+ echo >&2
843
+ fi
844
843
- return 0
845
+ return 0
846
}
847
848
set_netdata_updater_channel() {
847
- sed -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" -i "${NETDATA_USER_CONFIG_DIR}/.environment"
849
+ sed -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" -i "${NETDATA_USER_CONFIG_DIR}/.environment"
850
}
packaging/installer/kickstart-static64.sh
+4
-4
@@ -155,12 +155,12 @@ set_tarball_urls() {
155
}
156
157
safe_sha256sum() {
158
- # Within the contexct of the installer, we only use -c option that is common between the two commands
159
- # We will have to reconsider if we start non-common options
158
+ # Within the context of the installer, we only use -c option that is common between the two commands
159
+ # We will have to reconsider if we start using non-common options
160
if command -v sha256sum >/dev/null 2>&1; then
161
- sha256sum $@
161
+ sha256sum "$@"
162
elif command -v shasum >/dev/null 2>&1; then
163
- shasum -a 256 $@
163
+ shasum -a 256 "$@"
164
else
165
fatal "I could not find a suitable checksum binary to use"
166
fi