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