@cryptotaxi247 / netdata-1 / commits / 7c335a93b

Fixes support for uninstalling the eBPF collector in the uninstaller and fixes a minor bug (#8444)

* Fix bug in stop_all_netdata() to not try to kill netdata twice * Add uninstall support for eBPF Collector * Fixed typos

James Mills committed Mar 23, 2020 at 09:02 UTC 7c335a93bec2081ad9e7fe1a1f8b038ac56cfae3
2 files changed +358 -328
packaging/installer/functions.sh
+1 -1
@@ -594,7 +594,7 @@ stop_all_netdata() {
594 fi
595 fi
596
597 - if [ -n "$(netdata_pids)" ] || [ -n "$(builtin type -P netdatacli)" ]; then
597 + if [ -n "$(netdata_pids)" ] && [ -n "$(builtin type -P netdatacli)" ]; then
598 netdatacli shutdown-agent
599 sleep 20
600 fi
packaging/installer/netdata-uninstaller.sh
+357 -327
@@ -24,422 +24,450 @@ ENVIRONMENT_FILE="/etc/netdata/.environment"
24 INTERACTIVITY="-i"
25 YES=0
26 while :; do
27 - case "$1" in
28 - -h | --help)
29 - echo "$usage" >&2
30 - exit 1
31 - ;;
32 - -f | --force)
33 - INTERACTIVITY="-f"
34 - shift
35 - ;;
36 - -y | --yes)
37 - YES=1
38 - shift
39 - ;;
40 - -e | --env)
41 - ENVIRONMENT_FILE="$2"
42 - shift 2
43 - ;;
44 - -*)
45 - echo "$usage" >&2
46 - exit 1
47 - ;;
48 - *) break ;;
49 - esac
27 + case "$1" in
28 + -h | --help)
29 + echo "$usage" >&2
30 + exit 1
31 + ;;
32 + -f | --force)
33 + INTERACTIVITY="-f"
34 + shift
35 + ;;
36 + -y | --yes)
37 + YES=1
38 + shift
39 + ;;
40 + -e | --env)
41 + ENVIRONMENT_FILE="$2"
42 + shift 2
43 + ;;
44 + -*)
45 + echo "$usage" >&2
46 + exit 1
47 + ;;
48 + *) break ;;
49 + esac
50 done
51
52 if [ "$YES" != "1" ]; then
53 - echo >&2 "This script will REMOVE netdata from your system."
54 - echo >&2 "Run it again with --yes to do it."
55 - exit 1
53 + echo >&2 "This script will REMOVE netdata from your system."
54 + echo >&2 "Run it again with --yes to do it."
55 + exit 1
56 fi
57
58 if [[ $EUID -ne 0 ]]; then
59 - echo >&2 "This script SHOULD be run as root or otherwise it won't delete all installed components."
60 - key="n"
61 - read -r -s -n 1 -p "Do you want to continue as non-root user [y/n] ? " key
62 - if [ "$key" != "y" ] && [ "$key" != "Y" ]; then
63 - exit 1
64 - fi
59 + echo >&2 "This script SHOULD be run as root or otherwise it won't delete all installed components."
60 + key="n"
61 + read -r -s -n 1 -p "Do you want to continue as non-root user [y/n] ? " key
62 + if [ "$key" != "y" ] && [ "$key" != "Y" ]; then
63 + exit 1
64 + fi
65 fi
66
67 # -----------------------------------------------------------------------------
68 # portable service command
69
70 -service_cmd="$(command -v service 2>/dev/null)"
71 -rcservice_cmd="$(command -v rc-service 2>/dev/null)"
72 -systemctl_cmd="$(command -v systemctl 2>/dev/null)"
70 +service_cmd="$(command -v service 2> /dev/null)"
71 +rcservice_cmd="$(command -v rc-service 2> /dev/null)"
72 +systemctl_cmd="$(command -v systemctl 2> /dev/null)"
73 service() {
74
75 - local cmd="${1}" action="${2}"
76 -
77 - if [ -n "${systemctl_cmd}" ]; then
78 - run "${systemctl_cmd}" "${action}" "${cmd}"
79 - return $?
80 - elif [ -n "${service_cmd}" ]; then
81 - run "${service_cmd}" "${cmd}" "${action}"
82 - return $?
83 - elif [ -n "${rcservice_cmd}" ]; then
84 - run "${rcservice_cmd}" "${cmd}" "${action}"
85 - return $?
86 - fi
87 - return 1
75 + local cmd="${1}" action="${2}"
76 +
77 + if [ -n "${systemctl_cmd}" ]; then
78 + run "${systemctl_cmd}" "${action}" "${cmd}"
79 + return $?
80 + elif [ -n "${service_cmd}" ]; then
81 + run "${service_cmd}" "${cmd}" "${action}"
82 + return $?
83 + elif [ -n "${rcservice_cmd}" ]; then
84 + run "${rcservice_cmd}" "${cmd}" "${action}"
85 + return $?
86 + fi
87 + return 1
88 }
89
90 # -----------------------------------------------------------------------------
91
92 setup_terminal() {
93 - TPUT_RESET=""
94 - TPUT_YELLOW=""
95 - TPUT_WHITE=""
96 - TPUT_BGRED=""
97 - TPUT_BGGREEN=""
98 - TPUT_BOLD=""
99 - TPUT_DIM=""
100 -
101 - # Is stderr on the terminal? If not, then fail
102 - test -t 2 || return 1
103 -
104 - if command -v tput 1>/dev/null 2>&1; then
105 - if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
106 - # Enable colors
107 - TPUT_RESET="$(tput sgr 0)"
108 - TPUT_YELLOW="$(tput setaf 3)"
109 - TPUT_WHITE="$(tput setaf 7)"
110 - TPUT_BGRED="$(tput setab 1)"
111 - TPUT_BGGREEN="$(tput setab 2)"
112 - TPUT_BOLD="$(tput bold)"
113 - TPUT_DIM="$(tput dim)"
114 - fi
115 - fi
116 -
117 - return 0
93 + TPUT_RESET=""
94 + TPUT_YELLOW=""
95 + TPUT_WHITE=""
96 + TPUT_BGRED=""
97 + TPUT_BGGREEN=""
98 + TPUT_BOLD=""
99 + TPUT_DIM=""
100 +
101 + # Is stderr on the terminal? If not, then fail
102 + test -t 2 || return 1
103 +
104 + if command -v tput 1> /dev/null 2>&1; then
105 + if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
106 + # Enable colors
107 + TPUT_RESET="$(tput sgr 0)"
108 + TPUT_YELLOW="$(tput setaf 3)"
109 + TPUT_WHITE="$(tput setaf 7)"
110 + TPUT_BGRED="$(tput setab 1)"
111 + TPUT_BGGREEN="$(tput setab 2)"
112 + TPUT_BOLD="$(tput bold)"
113 + TPUT_DIM="$(tput dim)"
114 + fi
115 + fi
116 +
117 + return 0
118 }
119 -setup_terminal || echo >/dev/null
119 +setup_terminal || echo > /dev/null
120
121 run_ok() {
122 - printf >&2 "%s OK %s %s \n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${*}"
122 + printf >&2 "%s OK %s %s \n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${*}"
123 }
124
125 run_failed() {
126 - printf >&2 "%s FAILED %s %s \n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${*}"
126 + printf >&2 "%s FAILED %s %s \n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${*}"
127 }
128
129 ESCAPED_PRINT_METHOD=
130 -if printf "%q " test >/dev/null 2>&1; then
131 - ESCAPED_PRINT_METHOD="printfq"
130 +if printf "%q " test > /dev/null 2>&1; then
131 + ESCAPED_PRINT_METHOD="printfq"
132 fi
133 escaped_print() {
134 - if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
135 - printf "%q " "${@}"
136 - else
137 - printf "%s" "${*}"
138 - fi
139 - return 0
134 + if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
135 + printf "%q " "${@}"
136 + else
137 + printf "%s" "${*}"
138 + fi
139 + return 0
140 }
141
142 run_logfile="/dev/null"
143 run() {
144 - local user="${USER--}" dir="${PWD}" info info_console
145 -
146 - if [ "${UID}" = "0" ]; then
147 - info="[root ${dir}]# "
148 - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
149 - else
150 - info="[${user} ${dir}]$ "
151 - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
152 - fi
153 -
154 - {
155 - printf "%s" "${info}"
156 - escaped_print "${@}"
157 - printf "%s" " ... "
158 - } >> "${run_logfile}"
159 -
160 - printf "%s" >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
161 - escaped_print >&2 "${@}"
162 - printf "%s" >&2 "${TPUT_RESET}\n"
163 -
164 - "${@}"
165 -
166 - local ret=$?
167 - if [ ${ret} -ne 0 ]; then
168 - run_failed "${*}"
169 - printf >>"${run_logfile}" "FAILED with exit code %s\n" "${ret}"
170 - else
171 - run_ok "${*}"
172 - printf >>"${run_logfile}" "OK\n"
173 - fi
174 -
175 - return ${ret}
144 + local user="${USER--}" dir="${PWD}" info info_console
145 +
146 + if [ "${UID}" = "0" ]; then
147 + info="[root ${dir}]# "
148 + info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
149 + else
150 + info="[${user} ${dir}]$ "
151 + info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
152 + fi
153 +
154 + {
155 + printf "%s" "${info}"
156 + escaped_print "${@}"
157 + printf "%s" " ... "
158 + } >> "${run_logfile}"
159 +
160 + printf "%s" "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" >&2
161 + escaped_print >&2 "${@}"
162 + printf "%s" "${TPUT_RESET}\n" >&2
163 +
164 + "${@}"
165 +
166 + local ret=$?
167 + if [ ${ret} -ne 0 ]; then
168 + run_failed "${*}"
169 + printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
170 + else
171 + run_ok "${*}"
172 + printf >> "${run_logfile}" "OK\n"
173 + fi
174 +
175 + return ${ret}
176 }
177
178 portable_del_group() {
179 - local groupname="${1}"
180 -
181 - # Check if group exist
182 - echo >&2 "Removing ${groupname} user group ..."
183 -
184 - # Linux
185 - if command -v groupdel 1>/dev/null 2>&1; then
186 - if grep -q "${groupname}" /etc/group; then
187 - run groupdel "${groupname}" && return 0
188 - else
189 - echo >&2 "Group ${groupname} already removed in a previous step."
190 - run_ok "${*}"
191 - fi
192 - fi
193 -
194 - # mac OS
195 - if command -v dseditgroup 1> /dev/null 2>&1; then
196 - if dseditgroup -o read netdata 1> /dev/null 2>&1; then
197 - run dseditgroup -o delete "${groupname}" && return 0
198 - else
199 - echo >&2 "Could not find group ${groupname}, nothing to do"
200 - fi
201 - fi
202 -
203 - echo >&2 "Group ${groupname} was not automatically removed, you might have to remove it manually"
204 - return 1
179 + local groupname="${1}"
180 +
181 + # Check if group exist
182 + echo >&2 "Removing ${groupname} user group ..."
183 +
184 + # Linux
185 + if command -v groupdel 1> /dev/null 2>&1; then
186 + if grep -q "${groupname}" /etc/group; then
187 + run groupdel "${groupname}" && return 0
188 + else
189 + echo >&2 "Group ${groupname} already removed in a previous step."
190 + run_ok "${*}"
191 + fi
192 + fi
193 +
194 + # mac OS
195 + if command -v dseditgroup 1> /dev/null 2>&1; then
196 + if dseditgroup -o read netdata 1> /dev/null 2>&1; then
197 + run dseditgroup -o delete "${groupname}" && return 0
198 + else
199 + echo >&2 "Could not find group ${groupname}, nothing to do"
200 + fi
201 + fi
202 +
203 + echo >&2 "Group ${groupname} was not automatically removed, you might have to remove it manually"
204 + return 1
205 }
206
207 issystemd() {
208 - local pids p myns ns systemctl
208 + local pids p myns ns systemctl
209
210 - # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
211 - if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ] ; then
212 - return 1
213 - fi
210 + # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
211 + if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then
212 + return 1
213 + fi
214
215 - # if there is no systemctl command, it is not systemd
216 - systemctl=$(command -v systemctl 2>/dev/null)
217 - if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ] ; then
218 - return 1
219 - fi
215 + # if there is no systemctl command, it is not systemd
216 + systemctl=$(command -v systemctl 2> /dev/null)
217 + if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then
218 + return 1
219 + fi
220
221 - # if pid 1 is systemd, it is systemd
222 - [ "$(basename "$(readlink /proc/1/exe)" 2>/dev/null)" = "systemd" ] && return 0
221 + # if pid 1 is systemd, it is systemd
222 + [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
223
224 - # if systemd is not running, it is not systemd
225 - pids=$(safe_pidof systemd 2>/dev/null)
226 - [ -z "${pids}" ] && return 1
224 + # if systemd is not running, it is not systemd
225 + pids=$(safe_pidof systemd 2> /dev/null)
226 + [ -z "${pids}" ] && return 1
227
228 - # check if the running systemd processes are not in our namespace
229 - myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
230 - for p in ${pids}; do
231 - ns="$(readlink "/proc/${p}/ns/pid" 2>/dev/null)"
228 + # check if the running systemd processes are not in our namespace
229 + myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
230 + for p in ${pids}; do
231 + ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
232
233 - # if pid of systemd is in our namespace, it is systemd
234 - [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
235 - done
233 + # if pid of systemd is in our namespace, it is systemd
234 + [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
235 + done
236
237 - # else, it is not systemd
238 - return 1
237 + # else, it is not systemd
238 + return 1
239 }
240
241 portable_del_user() {
242 - local username="${1}"
243 - echo >&2 "Deleting ${username} user account ..."
242 + local username="${1}"
243 + echo >&2 "Deleting ${username} user account ..."
244
245 - # Linux
246 - if command -v userdel 1>/dev/null 2>&1; then
247 - run userdel -f "${username}" && return 0
248 - fi
245 + # Linux
246 + if command -v userdel 1> /dev/null 2>&1; then
247 + run userdel -f "${username}" && return 0
248 + fi
249
250 - # mac OS
251 - if command -v sysadminctl 1>/dev/null 2>&1; then
252 - run sysadminctl -deleteUser "${username}" && return 0
253 - fi
250 + # mac OS
251 + if command -v sysadminctl 1> /dev/null 2>&1; then
252 + run sysadminctl -deleteUser "${username}" && return 0
253 + fi
254
255 - echo >&2 "User ${username} could not be deleted from system, you might have to remove it manually"
256 - return 1
255 + echo >&2 "User ${username} could not be deleted from system, you might have to remove it manually"
256 + return 1
257 }
258
259 portable_del_user_from_group() {
260 - local groupname="${1}" username="${2}"
260 + local groupname="${1}" username="${2}"
261
262 - # username is not in group
263 - echo >&2 "Deleting ${username} user from ${groupname} group ..."
262 + # username is not in group
263 + echo >&2 "Deleting ${username} user from ${groupname} group ..."
264
265 - # Linux
266 - if command -v gpasswd 1>/dev/null 2>&1; then
267 - run gpasswd -d "netdata" "${group}" && return 0
268 - fi
265 + # Linux
266 + if command -v gpasswd 1> /dev/null 2>&1; then
267 + run gpasswd -d "netdata" "${group}" && return 0
268 + fi
269
270 - # FreeBSD
271 - if command -v pw 1>/dev/null 2>&1; then
272 - run pw groupmod "${groupname}" -d "${username}" && return 0
273 - fi
270 + # FreeBSD
271 + if command -v pw 1> /dev/null 2>&1; then
272 + run pw groupmod "${groupname}" -d "${username}" && return 0
273 + fi
274
275 - # BusyBox
276 - if command -v delgroup 1>/dev/null 2>&1; then
277 - run delgroup "${username}" "${groupname}" && return 0
278 - fi
275 + # BusyBox
276 + if command -v delgroup 1> /dev/null 2>&1; then
277 + run delgroup "${username}" "${groupname}" && return 0
278 + fi
279
280 - # mac OS
281 - if command -v dseditgroup 1> /dev/null 2>&1; then
282 - run dseditgroup -o delete -u "${username}" "${groupname}" && return 0
283 - fi
280 + # mac OS
281 + if command -v dseditgroup 1> /dev/null 2>&1; then
282 + run dseditgroup -o delete -u "${username}" "${groupname}" && return 0
283 + fi
284
285 - echo >&2 "Failed to delete user ${username} from group ${groupname} !"
286 - return 1
285 + echo >&2 "Failed to delete user ${username} from group ${groupname} !"
286 + return 1
287 }
288
289 quit_msg() {
290 - echo
291 - if [ "$FILE_REMOVAL_STATUS" -eq 0 ]; then
292 - echo >&2 "Something went wrong :("
293 - else
294 - echo >&2 "Netdata files were successfully removed from your system"
295 - fi
290 + echo
291 + if [ "$FILE_REMOVAL_STATUS" -eq 0 ]; then
292 + echo >&2 "Something went wrong :("
293 + else
294 + echo >&2 "Netdata files were successfully removed from your system"
295 + fi
296 }
297
298 user_input() {
299 - TEXT="$1"
300 - if [ "${INTERACTIVITY}" = "-i" ]; then
301 - read -r -p "$TEXT" >&2
302 - fi
299 + TEXT="$1"
300 + if [ "${INTERACTIVITY}" = "-i" ]; then
301 + read -r -p "$TEXT" >&2
302 + fi
303 }
304
305 rm_file() {
306 - FILE="$1"
307 - if [ -f "${FILE}" ]; then
308 - run rm -v ${INTERACTIVITY} "${FILE}"
309 - fi
306 + FILE="$1"
307 + if [ -f "${FILE}" ]; then
308 + run rm -v ${INTERACTIVITY} "${FILE}"
309 + fi
310 }
311
312 rm_dir() {
313 - DIR="$1"
314 - if [ -n "$DIR" ] && [ -d "$DIR" ]; then
315 - user_input "Press ENTER to recursively delete directory '$DIR' > "
316 - run rm -v -f -R "${DIR}"
317 - fi
313 + DIR="$1"
314 + if [ -n "$DIR" ] && [ -d "$DIR" ]; then
315 + user_input "Press ENTER to recursively delete directory '$DIR' > "
316 + run rm -v -f -R "${DIR}"
317 + fi
318 }
319
320 safe_pidof() {
321 - local pidof_cmd
322 - pidof_cmd="$(command -v pidof 2>/dev/null)"
323 - if [ -n "${pidof_cmd}" ]; then
324 - ${pidof_cmd} "${@}"
325 - return $?
326 - else
327 - ps -acxo pid,comm |
328 - sed "s/^ *//g" |
329 - grep netdata |
330 - cut -d ' ' -f 1
331 - return $?
332 - fi
321 + local pidof_cmd
322 + pidof_cmd="$(command -v pidof 2> /dev/null)"
323 + if [ -n "${pidof_cmd}" ]; then
324 + ${pidof_cmd} "${@}"
325 + return $?
326 + else
327 + ps -acxo pid,comm |
328 + sed "s/^ *//g" |
329 + grep netdata |
330 + cut -d ' ' -f 1
331 + return $?
332 + fi
333 }
334
335 pidisnetdata() {
336 - if [ -d /proc/self ]; then
337 - if [ -z "$1" ] || [ ! -f "/proc/$1/stat" ] ; then
338 - return 1
339 - fi
340 - [ "$(cut -d '(' -f 2 "/proc/$1/stat" | cut -d ')' -f 1)" = "netdata" ] && return 0
341 - return 1
342 - fi
343 - return 0
336 + if [ -d /proc/self ]; then
337 + if [ -z "$1" ] || [ ! -f "/proc/$1/stat" ]; then
338 + return 1
339 + fi
340 + [ "$(cut -d '(' -f 2 "/proc/$1/stat" | cut -d ')' -f 1)" = "netdata" ] && return 0
341 + return 1
342 + fi
343 + return 0
344 }
345
346 stop_netdata_on_pid() {
347 - local pid="${1}" ret=0 count=0
347 + local pid="${1}" ret=0 count=0
348
349 - pidisnetdata "${pid}" || return 0
349 + pidisnetdata "${pid}" || return 0
350
351 - printf >&2 "Stopping netdata on pid %s ..." "${pid}"
352 - while [ -n "$pid" ] && [ ${ret} -eq 0 ]; do
353 - if [ ${count} -gt 24 ]; then
354 - echo >&2 "Cannot stop the running netdata on pid ${pid}."
355 - return 1
356 - fi
351 + printf >&2 "Stopping netdata on pid %s ..." "${pid}"
352 + while [ -n "$pid" ] && [ ${ret} -eq 0 ]; do
353 + if [ ${count} -gt 24 ]; then
354 + echo >&2 "Cannot stop the running netdata on pid ${pid}."
355 + return 1
356 + fi
357
358 - count=$((count + 1))
358 + count=$((count + 1))
359
360 - pidisnetdata "${pid}" || ret=1
361 - if [ ${ret} -eq 1 ] ; then
362 - break
363 - fi
360 + pidisnetdata "${pid}" || ret=1
361 + if [ ${ret} -eq 1 ]; then
362 + break
363 + fi
364
365 - if [ ${count} -lt 12 ] ; then
366 - run kill "${pid}" 2>/dev/null
367 - ret=$?
368 - else
369 - run kill -9 "${pid}" 2>/dev/null
370 - ret=$?
371 - fi
365 + if [ ${count} -lt 12 ]; then
366 + run kill "${pid}" 2> /dev/null
367 + ret=$?
368 + else
369 + run kill -9 "${pid}" 2> /dev/null
370 + ret=$?
371 + fi
372
373 - test ${ret} -eq 0 && printf >&2 "." && sleep 5
373 + test ${ret} -eq 0 && printf >&2 "." && sleep 5
374
375 - done
375 + done
376
377 - echo >&2
378 - if [ ${ret} -eq 0 ]; then
379 - echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
380 - return 1
381 - fi
377 + echo >&2
378 + if [ ${ret} -eq 0 ]; then
379 + echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
380 + return 1
381 + fi
382
383 - echo >&2 "netdata on pid ${pid} stopped."
384 - return 0
383 + echo >&2 "netdata on pid ${pid} stopped."
384 + return 0
385 }
386
387 netdata_pids() {
388 - local p myns ns
388 + local p myns ns
389
390 - myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
390 + myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
391
392 - for p in \
393 - $(cat /var/run/netdata.pid 2>/dev/null) \
394 - $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
395 - $(safe_pidof netdata 2>/dev/null); do
396 - ns="$(readlink "/proc/${p}/ns/pid" 2>/dev/null)"
392 + for p in \
393 + $(cat /var/run/netdata.pid 2> /dev/null) \
394 + $(cat /var/run/netdata/netdata.pid 2> /dev/null) \
395 + $(safe_pidof netdata 2> /dev/null); do
396 + ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
397
398 - if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
399 - pidisnetdata "${p}" && echo "${p}"
400 - fi
401 - done
398 + if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
399 + pidisnetdata "${p}" && echo "${p}"
400 + fi
401 + done
402 }
403
404 stop_all_netdata() {
405 - local p
406 -
407 - if [ "${UID}" -eq 0 ] ; then
408 - uname="$(uname 2>/dev/null)"
409 -
410 - # Any of these may fail, but we need to not bail if they do.
411 - if issystemd; then
412 - if systemctl stop netdata ; then
413 - sleep 5
414 - fi
415 - elif [ "${uname}" = "Darwin" ]; then
416 - if launchctl stop netdata ; then
417 - sleep 5
418 - fi
419 - elif [ "${uname}" = "FreeBSD" ]; then
420 - if /etc/rc.d/netdata stop ; then
421 - sleep 5
422 - fi
423 - else
424 - if service netdata stop ; then
425 - sleep 5
426 - fi
427 - fi
428 - fi
429 -
430 - if [ -n "$(netdata_pids)" ] && [ -n "$(builtin type -P netdatacli)" ] ; then
431 - netdatacli shutdown-agent
432 - sleep 20
433 - fi
434 -
435 - for p in $(netdata_pids); do
436 - # shellcheck disable=SC2086
437 - stop_netdata_on_pid ${p}
438 - done
405 + local p
406 +
407 + if [ "${UID}" -eq 0 ]; then
408 + uname="$(uname 2> /dev/null)"
409 +
410 + # Any of these may fail, but we need to not bail if they do.
411 + if issystemd; then
412 + if systemctl stop netdata; then
413 + sleep 5
414 + fi
415 + elif [ "${uname}" = "Darwin" ]; then
416 + if launchctl stop netdata; then
417 + sleep 5
418 + fi
419 + elif [ "${uname}" = "FreeBSD" ]; then
420 + if /etc/rc.d/netdata stop; then
421 + sleep 5
422 + fi
423 + else
424 + if service netdata stop; then
425 + sleep 5
426 + fi
427 + fi
428 + fi
429 +
430 + if [ -n "$(netdata_pids)" ] && [ -n "$(builtin type -P netdatacli)" ]; then
431 + netdatacli shutdown-agent
432 + sleep 20
433 + fi
434 +
435 + for p in $(netdata_pids); do
436 + # shellcheck disable=SC2086
437 + stop_netdata_on_pid ${p}
438 + done
439 }
440
441 trap quit_msg EXIT
442
443 +uninstall_ebpf() {
444 + # Removing NetData's libexec directory is taken care of which is where we
445 + # installed the rest of the shared libraires for the eBPF Collector.
446 +
447 + echo >&2 " Finding lib directory ..."
448 + libdir=
449 + libdir="$(ldconfig -v 2> /dev/null | grep ':$' | sed -e 's/://' | sort -r | grep 'usr' | head -n 1)"
450 + if [ -z "${libdir}" ]; then
451 + libdir="$(ldconfig -v 2> /dev/null | grep ':$' | sed -e 's/://' | sort -r | head -n 1)"
452 + fi
453 +
454 + if [ -z "${libdir}" ]; then
455 + echo >&2 "Unable to find the system lib directory we installed eBPF ebpf_kernel.so to ..."
456 + user_input "Press ENTER to search your system (which may take some time) ..."
457 + find / -type f -name 'libbpf_kernel.so' -o -name 'libbpf_kernel.so.0'
458 + echo >&2 "Please manually delete these files"
459 + return 1
460 + fi
461 +
462 + rm_file "${libdir}/libbpf_kernel.so.0"
463 + rm_file "${libdir}/libbpf_kernel.so"
464 + run ldconfig
465 +
466 + echo >&2 "ePBF uninstall all done!"
467 +
468 + return 0
469 +}
470 +
471 #shellcheck source=/dev/null
472 source "${ENVIRONMENT_FILE}" || exit 1
473
@@ -457,28 +485,30 @@ rm_file /etc/periodic/daily/netdata-updater
485 rm_file /etc/cron.daily/netdata-updater
486
487 if [ -n "${NETDATA_PREFIX}" ] && [ -d "${NETDATA_PREFIX}" ]; then
460 - rm_dir "${NETDATA_PREFIX}"
488 + rm_dir "${NETDATA_PREFIX}"
489 else
462 - rm_file "/usr/sbin/netdata"
463 - rm_file "/usr/sbin/netdatacli"
464 - rm_file "/tmp/netdata-ipc"
465 - rm_file "/usr/sbin/netdata-claim.sh"
466 - rm_dir "/usr/share/netdata"
467 - rm_dir "/usr/libexec/netdata"
468 - rm_dir "/var/lib/netdata"
469 - rm_dir "/var/cache/netdata"
470 - rm_dir "/var/log/netdata"
471 - rm_dir "/etc/netdata"
490 + rm_file "/usr/sbin/netdata"
491 + rm_file "/usr/sbin/netdatacli"
492 + rm_file "/tmp/netdata-ipc"
493 + rm_file "/usr/sbin/netdata-claim.sh"
494 + rm_dir "/usr/share/netdata"
495 + rm_dir "/usr/libexec/netdata"
496 + rm_dir "/var/lib/netdata"
497 + rm_dir "/var/cache/netdata"
498 + rm_dir "/var/log/netdata"
499 + rm_dir "/etc/netdata"
500 fi
501
502 +uninstall_ebpf || echo >&2 "Unable to remove eBPF files automatically"
503 +
504 FILE_REMOVAL_STATUS=1
505
506 #### REMOVE NETDATA USER FROM ADDED GROUPS
507 if [ -n "$NETDATA_ADDED_TO_GROUPS" ]; then
478 - user_input "Press ENTER to delete 'netdata' from following groups: '$NETDATA_ADDED_TO_GROUPS' > "
479 - for group in $NETDATA_ADDED_TO_GROUPS; do
480 - portable_del_user_from_group "${group}" "netdata"
481 - done
508 + user_input "Press ENTER to delete 'netdata' from following groups: '$NETDATA_ADDED_TO_GROUPS' > "
509 + for group in $NETDATA_ADDED_TO_GROUPS; do
510 + portable_del_user_from_group "${group}" "netdata"
511 + done
512 fi
513
514 #### REMOVE USER