netdata-uninstaller.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. #!/bin/sh
  2. #
  3. # This is the netdata uninstaller script
  4. #
  5. # Variables needed by script and taken from '.environment' file:
  6. # - NETDATA_PREFIX
  7. # - NETDATA_ADDED_TO_GROUPS
  8. #
  9. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  10. #
  11. # Author: Paweł Krupa <paulfantom@gmail.com>
  12. # Author: Pavlos Emm. Katsoulakis <paul@netdata.cloud>
  13. usage="$(basename "$0") [-h] [-f ] -- program to calculate the answer to life, the universe and everything
  14. where:
  15. -e, --env path to environment file (defaults to '/etc/netdata/.environment'
  16. -f, --force force uninstallation and do not ask any questions
  17. -h show this help text
  18. -y, --yes flag needs to be set to proceed with uninstallation"
  19. FILE_REMOVAL_STATUS=0
  20. ENVIRONMENT_FILE="/etc/netdata/.environment"
  21. # shellcheck disable=SC2034
  22. INTERACTIVITY="-i"
  23. YES=0
  24. while :; do
  25. case "$1" in
  26. -h | --help)
  27. echo "$usage" >&2
  28. exit 1
  29. ;;
  30. -f | --force)
  31. INTERACTIVITY="-f"
  32. shift
  33. ;;
  34. -y | --yes)
  35. YES=1
  36. FLAG=-y
  37. shift
  38. ;;
  39. -e | --env)
  40. ENVIRONMENT_FILE="$2"
  41. shift 2
  42. ;;
  43. -*)
  44. echo "$usage" >&2
  45. exit 1
  46. ;;
  47. *) break ;;
  48. esac
  49. done
  50. if [ "$YES" != "1" ]; then
  51. echo >&2 "This script will REMOVE netdata from your system."
  52. echo >&2 "Run it again with --yes to do it."
  53. exit 1
  54. fi
  55. if [ "$(id -u)" -ne 0 ]; then
  56. echo >&2 "This script SHOULD be run as root or otherwise it won't delete all installed components."
  57. key="n"
  58. read -r 1 -p "Do you want to continue as non-root user [y/n] ? " key
  59. if [ "$key" != "y" ] && [ "$key" != "Y" ]; then
  60. exit 1
  61. fi
  62. fi
  63. user_input() {
  64. if [ "${INTERACTIVITY}" = "-i" ]; then
  65. TEXT="$1 [y/n]"
  66. while true; do
  67. echo "$TEXT"
  68. read -r yn
  69. case "$yn" in
  70. [Yy]*) return 0;;
  71. [Nn]*) return 1;;
  72. *) echo "Please answer yes or no.";;
  73. esac
  74. done
  75. fi
  76. }
  77. _cannot_use_tmpdir() {
  78. testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
  79. ret=0
  80. if [ -z "${testfile}" ]; then
  81. return "${ret}"
  82. fi
  83. if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
  84. if chmod +x "${testfile}"; then
  85. if [ "$("${testfile}")" = "SUCCESS" ]; then
  86. ret=1
  87. fi
  88. fi
  89. fi
  90. rm -f "${testfile}"
  91. return "${ret}"
  92. }
  93. create_tmp_directory() {
  94. if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
  95. if _cannot_use_tmpdir /tmp; then
  96. if _cannot_use_tmpdir "${PWD}"; then
  97. fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." F0400
  98. else
  99. TMPDIR="${PWD}"
  100. fi
  101. else
  102. TMPDIR="/tmp"
  103. fi
  104. fi
  105. mktemp -d -t netdata-kickstart-XXXXXXXXXX
  106. }
  107. tmpdir="$(create_tmp_directory)"
  108. detect_existing_install() {
  109. if pkg_installed netdata; then
  110. ndprefix="/"
  111. else
  112. if [ -n "${INSTALL_PREFIX}" ]; then
  113. searchpath="${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}"
  114. searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}"
  115. else
  116. searchpath="${PATH}"
  117. fi
  118. ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
  119. if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ]; then
  120. ndpath="/opt/netdata/bin/netdata"
  121. fi
  122. if [ -n "${ndpath}" ]; then
  123. ndprefix="$(dirname "$(dirname "${ndpath}")")"
  124. fi
  125. if echo "${ndprefix}" | grep -Eq '/usr$'; then
  126. ndprefix="$(dirname "${ndprefix}")"
  127. fi
  128. fi
  129. if [ -n "${ndprefix}" ]; then
  130. typefile="${ndprefix}/etc/netdata/.install-type"
  131. envfile="${ndprefix}/etc/netdata/.environment"
  132. if [ -r "${typefile}" ]; then
  133. ${ROOTCMD} sh -c "cat \"${typefile}\" > \"${tmpdir}/install-type\""
  134. # shellcheck disable=SC1090,SC1091
  135. . "${tmpdir}/install-type"
  136. else
  137. INSTALL_TYPE="unknown"
  138. fi
  139. if [ "${INSTALL_TYPE}" = "unknown" ] || [ "${INSTALL_TYPE}" = "custom" ]; then
  140. if [ -r "${envfile}" ]; then
  141. ${ROOTCMD} sh -c "cat \"${envfile}\" > \"${tmpdir}/environment\""
  142. # shellcheck disable=SC1091
  143. . "${tmpdir}/environment"
  144. if [ -n "${NETDATA_IS_STATIC_INSTALL}" ]; then
  145. if [ "${NETDATA_IS_STATIC_INSTALL}" = "yes" ]; then
  146. INSTALL_TYPE="legacy-static"
  147. else
  148. INSTALL_TYPE="legacy-build"
  149. fi
  150. fi
  151. fi
  152. fi
  153. fi
  154. }
  155. pkg_installed() {
  156. case "${DISTRO_COMPAT_NAME}" in
  157. debian|ubuntu)
  158. dpkg-query --show --showformat '${Status}' "${1}" 2>&1 | cut -f 1 -d ' ' | grep -q '^install$'
  159. return $?
  160. ;;
  161. centos|fedora|opensuse|ol)
  162. rpm -q "${1}" > /dev/null 2>&1
  163. return $?
  164. ;;
  165. *)
  166. return 1
  167. ;;
  168. esac
  169. }
  170. detect_existing_install
  171. if [ -x "$(command -v apt-get)" ] && [ "${INSTALL_TYPE}" = "binpkg-deb" ]; then
  172. if dpkg -s netdata > /dev/null; then
  173. echo "Found netdata native installation"
  174. if user_input "Do you want to remove netdata? "; then
  175. apt-get remove netdata ${FLAG}
  176. fi
  177. if dpkg -s netdata-repo-edge > /dev/null; then
  178. if user_input "Do you want to remove netdata-repo-edge? "; then
  179. apt-get remove netdata-repo-edge ${FLAG}
  180. fi
  181. fi
  182. if dpkg -s netdata-repo > /dev/null; then
  183. if user_input "Do you want to remove netdata-repo? "; then
  184. apt-get remove netdata-repo ${FLAG}
  185. fi
  186. fi
  187. exit 0
  188. fi
  189. elif [ -x "$(command -v dnf)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
  190. if rpm -q netdata > /dev/null; then
  191. echo "Found netdata native installation."
  192. if user_input "Do you want to remove netdata? "; then
  193. dnf remove netdata ${FLAG}
  194. fi
  195. if rpm -q netdata-repo-edge > /dev/null; then
  196. if user_input "Do you want to remove netdata-repo-edge? "; then
  197. dnf remove netdata-repo-edge ${FLAG}
  198. fi
  199. fi
  200. if rpm -q netdata-repo > /dev/null; then
  201. if user_input "Do you want to remove netdata-repo? "; then
  202. dnf remove netdata-repo ${FLAG}
  203. fi
  204. fi
  205. exit 0
  206. fi
  207. elif [ -x "$(command -v yum)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
  208. if rpm -q netdata > /dev/null; then
  209. echo "Found netdata native installation."
  210. if user_input "Do you want to remove netdata? "; then
  211. yum remove netdata ${FLAG}
  212. fi
  213. if rpm -q netdata-repo-edge > /dev/null; then
  214. if user_input "Do you want to remove netdata-repo-edge? "; then
  215. yum remove netdata-repo-edge ${FLAG}
  216. fi
  217. fi
  218. if rpm -q netdata-repo > /dev/null; then
  219. if user_input "Do you want to remove netdata-repo? "; then
  220. yum remove netdata-repo ${FLAG}
  221. fi
  222. fi
  223. exit 0
  224. fi
  225. elif [ -x "$(command -v zypper)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then
  226. if [ "${FLAG}" = "-y" ]; then
  227. FLAG=-n
  228. fi
  229. if zypper search -i netdata > /dev/null; then
  230. echo "Found netdata native installation."
  231. if user_input "Do you want to remove netdata? "; then
  232. zypper ${FLAG} remove netdata
  233. fi
  234. if zypper search -i netdata-repo-edge > /dev/null; then
  235. if user_input "Do you want to remove netdata-repo-edge? "; then
  236. zypper ${FLAG} remove netdata-repo-edge
  237. fi
  238. fi
  239. if zypper search -i netdata-repo > /dev/null; then
  240. if user_input "Do you want to remove netdata-repo? "; then
  241. zypper ${FLAG} remove netdata-repo
  242. fi
  243. fi
  244. exit 0
  245. fi
  246. fi
  247. # -----------------------------------------------------------------------------
  248. # portable service command
  249. service_cmd="$(command -v service 2> /dev/null)"
  250. rcservice_cmd="$(command -v rc-service 2> /dev/null)"
  251. systemctl_cmd="$(command -v systemctl 2> /dev/null)"
  252. service() {
  253. cmd="${1}"
  254. action="${2}"
  255. if [ -n "${systemctl_cmd}" ]; then
  256. run "${systemctl_cmd}" "${action}" "${cmd}"
  257. return $?
  258. elif [ -n "${service_cmd}" ]; then
  259. run "${service_cmd}" "${cmd}" "${action}"
  260. return $?
  261. elif [ -n "${rcservice_cmd}" ]; then
  262. run "${rcservice_cmd}" "${cmd}" "${action}"
  263. return $?
  264. fi
  265. return 1
  266. }
  267. # -----------------------------------------------------------------------------
  268. setup_terminal() {
  269. TPUT_RESET=""
  270. TPUT_YELLOW=""
  271. TPUT_WHITE=""
  272. TPUT_BGRED=""
  273. TPUT_BGGREEN=""
  274. TPUT_BOLD=""
  275. TPUT_DIM=""
  276. # Is stderr on the terminal? If not, then fail
  277. test -t 2 || return 1
  278. if command -v tput 1> /dev/null 2>&1; then
  279. if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
  280. # Enable colors
  281. TPUT_RESET="$(tput sgr 0)"
  282. TPUT_YELLOW="$(tput setaf 3)"
  283. TPUT_WHITE="$(tput setaf 7)"
  284. TPUT_BGRED="$(tput setab 1)"
  285. TPUT_BGGREEN="$(tput setab 2)"
  286. TPUT_BOLD="$(tput bold)"
  287. TPUT_DIM="$(tput dim)"
  288. fi
  289. fi
  290. return 0
  291. }
  292. setup_terminal || echo > /dev/null
  293. run_ok() {
  294. printf >&2 "%s OK %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
  295. }
  296. run_failed() {
  297. printf >&2 "%s FAILED %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}"
  298. }
  299. ESCAPED_PRINT_METHOD=
  300. if printf "%s " test > /dev/null 2>&1; then
  301. ESCAPED_PRINT_METHOD="printfq"
  302. fi
  303. escaped_print() {
  304. if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
  305. printf "%s " "${@}"
  306. else
  307. printf "%s" "${*}"
  308. fi
  309. return 0
  310. }
  311. run_logfile="/dev/null"
  312. run() {
  313. user="${USER--}"
  314. dir="${PWD}"
  315. if [ "$(id -u)" = "0" ]; then
  316. info="[root ${dir}]# "
  317. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
  318. else
  319. info="[${user} ${dir}]$ "
  320. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
  321. fi
  322. {
  323. printf "%s" "${info}"
  324. escaped_print "${@}"
  325. printf "%s" " ... "
  326. } >> "${run_logfile}"
  327. printf "%s" "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" >&2
  328. escaped_print >&2 "${@}"
  329. printf "%s\n" "${TPUT_RESET}" >&2
  330. "${@}"
  331. ret=$?
  332. if [ ${ret} -ne 0 ]; then
  333. run_failed
  334. printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
  335. else
  336. run_ok
  337. printf >> "${run_logfile}" "OK\n"
  338. fi
  339. return ${ret}
  340. }
  341. portable_del_group() {
  342. groupname="${1}"
  343. # Check if group exist
  344. echo >&2 "Removing ${groupname} user group ..."
  345. # Linux
  346. if command -v groupdel 1> /dev/null 2>&1; then
  347. if grep -q "${groupname}" /etc/group; then
  348. run groupdel "${groupname}" && return 0
  349. else
  350. echo >&2 "Group ${groupname} already removed in a previous step."
  351. return 0
  352. fi
  353. fi
  354. # mac OS
  355. if command -v dseditgroup 1> /dev/null 2>&1; then
  356. if dseditgroup -o read netdata 1> /dev/null 2>&1; then
  357. run dseditgroup -o delete "${groupname}" && return 0
  358. else
  359. echo >&2 "Could not find group ${groupname}, nothing to do"
  360. return 0
  361. fi
  362. fi
  363. echo >&2 "Group ${groupname} was not automatically removed, you might have to remove it manually"
  364. return 1
  365. }
  366. issystemd() {
  367. pids=''
  368. p=''
  369. myns=''
  370. ns=''
  371. systemctl=''
  372. # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
  373. if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then
  374. return 1
  375. fi
  376. # if there is no systemctl command, it is not systemd
  377. systemctl=$(command -v systemctl 2> /dev/null)
  378. if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then
  379. return 1
  380. fi
  381. # if pid 1 is systemd, it is systemd
  382. [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
  383. # if systemd is not running, it is not systemd
  384. pids=$(safe_pidof systemd 2> /dev/null)
  385. [ -z "${pids}" ] && return 1
  386. # check if the running systemd processes are not in our namespace
  387. myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
  388. for p in ${pids}; do
  389. ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
  390. # if pid of systemd is in our namespace, it is systemd
  391. [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
  392. done
  393. # else, it is not systemd
  394. return 1
  395. }
  396. portable_del_user() {
  397. username="${1}"
  398. echo >&2 "Deleting ${username} user account ..."
  399. # Linux
  400. if command -v userdel 1> /dev/null 2>&1; then
  401. run userdel -f "${username}" && return 0
  402. fi
  403. # mac OS
  404. if command -v sysadminctl 1> /dev/null 2>&1; then
  405. run sysadminctl -deleteUser "${username}" && return 0
  406. fi
  407. echo >&2 "User ${username} could not be deleted from system, you might have to remove it manually"
  408. return 1
  409. }
  410. portable_del_user_from_group() {
  411. groupname="${1}"
  412. username="${2}"
  413. # username is not in group
  414. echo >&2 "Deleting ${username} user from ${groupname} group ..."
  415. # Linux
  416. if command -v gpasswd 1> /dev/null 2>&1; then
  417. run gpasswd -d "netdata" "${group}" && return 0
  418. fi
  419. # FreeBSD
  420. if command -v pw 1> /dev/null 2>&1; then
  421. run pw groupmod "${groupname}" -d "${username}" && return 0
  422. fi
  423. # BusyBox
  424. if command -v delgroup 1> /dev/null 2>&1; then
  425. run delgroup "${username}" "${groupname}" && return 0
  426. fi
  427. # mac OS
  428. if command -v dseditgroup 1> /dev/null 2>&1; then
  429. run dseditgroup -o delete -u "${username}" "${groupname}" && return 0
  430. fi
  431. echo >&2 "Failed to delete user ${username} from group ${groupname} !"
  432. return 1
  433. }
  434. quit_msg() {
  435. echo
  436. if [ "$FILE_REMOVAL_STATUS" -eq 0 ]; then
  437. echo >&2 "Something went wrong :("
  438. else
  439. echo >&2 "Netdata files were successfully removed from your system"
  440. fi
  441. }
  442. rm_file() {
  443. FILE="$1"
  444. if [ -f "${FILE}" ]; then
  445. if user_input "Do you want to delete this file '$FILE' ? "; then
  446. run rm -v "${FILE}"
  447. fi
  448. fi
  449. }
  450. rm_dir() {
  451. DIR="$1"
  452. if [ -n "$DIR" ] && [ -d "$DIR" ]; then
  453. if user_input "Do you want to delete this directory '$DIR' ? "; then
  454. run rm -v -f -R "${DIR}"
  455. fi
  456. fi
  457. }
  458. safe_pidof() {
  459. pidof_cmd="$(command -v pidof 2> /dev/null)"
  460. if [ -n "${pidof_cmd}" ]; then
  461. ${pidof_cmd} "${@}"
  462. return $?
  463. else
  464. ps -acxo pid,comm |
  465. sed "s/^ *//g" |
  466. grep netdata |
  467. cut -d ' ' -f 1
  468. return $?
  469. fi
  470. }
  471. pidisnetdata() {
  472. if [ -d /proc/self ]; then
  473. if [ -z "$1" ] || [ ! -f "/proc/$1/stat" ]; then
  474. return 1
  475. fi
  476. [ "$(cut -d '(' -f 2 "/proc/$1/stat" | cut -d ')' -f 1)" = "netdata" ] && return 0
  477. return 1
  478. fi
  479. return 0
  480. }
  481. stop_netdata_on_pid() {
  482. pid="${1}"
  483. ret=0
  484. count=0
  485. pidisnetdata "${pid}" || return 0
  486. printf >&2 "Stopping netdata on pid %s ..." "${pid}"
  487. while [ -n "$pid" ] && [ ${ret} -eq 0 ]; do
  488. if [ ${count} -gt 24 ]; then
  489. echo >&2 "Cannot stop the running netdata on pid ${pid}."
  490. return 1
  491. fi
  492. count=$((count + 1))
  493. pidisnetdata "${pid}" || ret=1
  494. if [ ${ret} -eq 1 ]; then
  495. break
  496. fi
  497. if [ ${count} -lt 12 ]; then
  498. run kill "${pid}" 2> /dev/null
  499. ret=$?
  500. else
  501. run kill -9 "${pid}" 2> /dev/null
  502. ret=$?
  503. fi
  504. test ${ret} -eq 0 && printf >&2 "." && sleep 5
  505. done
  506. echo >&2
  507. if [ ${ret} -eq 0 ]; then
  508. echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
  509. return 1
  510. fi
  511. echo >&2 "netdata on pid ${pid} stopped."
  512. return 0
  513. }
  514. netdata_pids() {
  515. p=''
  516. ns=''
  517. myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
  518. for p in \
  519. $(cat /var/run/netdata.pid 2> /dev/null) \
  520. $(cat /var/run/netdata/netdata.pid 2> /dev/null) \
  521. $(safe_pidof netdata 2> /dev/null); do
  522. ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
  523. if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
  524. pidisnetdata "${p}" && echo "${p}"
  525. fi
  526. done
  527. }
  528. stop_all_netdata() {
  529. p=''
  530. if [ "$(id -u)" -eq 0 ]; then
  531. uname="$(uname 2> /dev/null)"
  532. # Any of these may fail, but we need to not bail if they do.
  533. if issystemd; then
  534. if systemctl stop netdata; then
  535. sleep 5
  536. fi
  537. elif [ "${uname}" = "Darwin" ]; then
  538. if launchctl stop netdata; then
  539. sleep 5
  540. fi
  541. elif [ "${uname}" = "FreeBSD" ]; then
  542. if /etc/rc.d/netdata stop; then
  543. sleep 5
  544. fi
  545. else
  546. if service netdata stop; then
  547. sleep 5
  548. fi
  549. fi
  550. fi
  551. if [ -n "$(netdata_pids)" ] && [ -n "$(command -v netdatacli)" ]; then
  552. netdatacli shutdown-agent
  553. sleep 20
  554. fi
  555. for p in $(netdata_pids); do
  556. # shellcheck disable=SC2086
  557. stop_netdata_on_pid ${p}
  558. done
  559. }
  560. trap quit_msg EXIT
  561. # shellcheck source=/dev/null
  562. # shellcheck disable=SC1090
  563. . "${ENVIRONMENT_FILE}" || exit 1
  564. #### STOP NETDATA
  565. echo >&2 "Stopping a possibly running netdata..."
  566. stop_all_netdata
  567. #### REMOVE NETDATA FILES
  568. rm_file /etc/logrotate.d/netdata
  569. rm_file /etc/systemd/system/netdata.service
  570. rm_file /lib/systemd/system/netdata.service
  571. rm_file /usr/lib/systemd/system/netdata.service
  572. rm_file /etc/systemd/system/netdata-updater.service
  573. rm_file /lib/systemd/system/netdata-updater.service
  574. rm_file /usr/lib/systemd/system/netdata-updater.service
  575. rm_file /etc/systemd/system/netdata-updater.timer
  576. rm_file /lib/systemd/system/netdata-updater.timer
  577. rm_file /usr/lib/systemd/system/netdata-updater.timer
  578. rm_file /etc/init.d/netdata
  579. rm_file /etc/periodic/daily/netdata-updater
  580. rm_file /etc/cron.daily/netdata-updater
  581. rm_file /etc/cron.d/netdata-updater
  582. if [ -n "${NETDATA_PREFIX}" ] && [ -d "${NETDATA_PREFIX}" ]; then
  583. rm_dir "${NETDATA_PREFIX}"
  584. else
  585. rm_file "/usr/sbin/netdata"
  586. rm_file "/usr/sbin/netdatacli"
  587. rm_file "/tmp/netdata-ipc"
  588. rm_file "/usr/sbin/netdata-claim.sh"
  589. rm_dir "/usr/share/netdata"
  590. rm_dir "/usr/libexec/netdata"
  591. rm_dir "/var/lib/netdata"
  592. rm_dir "/var/cache/netdata"
  593. rm_dir "/var/log/netdata"
  594. rm_dir "/etc/netdata"
  595. fi
  596. FILE_REMOVAL_STATUS=1
  597. #### REMOVE NETDATA USER FROM ADDED GROUPS
  598. if [ -n "$NETDATA_ADDED_TO_GROUPS" ]; then
  599. if user_input "Do you want to delete 'netdata' from following groups: '$NETDATA_ADDED_TO_GROUPS' ? "; then
  600. for group in $NETDATA_ADDED_TO_GROUPS; do
  601. portable_del_user_from_group "${group}" "netdata"
  602. done
  603. fi
  604. fi
  605. #### REMOVE USER
  606. if user_input "Do you want to delete 'netdata' system user ? "; then
  607. portable_del_user "netdata" || :
  608. fi
  609. ### REMOVE GROUP
  610. if user_input "Do you want to delete 'netdata' system group ? "; then
  611. portable_del_group "netdata" || :
  612. fi