forked from prahaladramji/synology-prometheus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuninstall
48 lines (43 loc) · 1.77 KB
/
uninstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env sh
# Global Variables
VERSION=$(curl -fsSL https://raw.githubusercontent.com/billykwooten/synology-prometheus/master/version | cat)
DOCKER_VOLUME="/volume1/docker"
PROMETHEUS_ROOT="${DOCKER_VOLUME}/prometheus"
GRAFANA_ROOT="${DOCKER_VOLUME}/grafana"
ALERTMANAGER_ROOT="${DOCKER_VOLUME}/alertmanager"
ALERTMANAGER_ID=$(docker ps -a | grep alertmanager | awk '{print $1}')
PROMETHEUS_ID=$(docker ps -a | grep -w "prometheus" | awk '{print $1}')
GRAFANA_ID=$(docker ps -a | grep grafana | awk '{print $1}')
NODE_EXPORTER_ID=$(docker ps -a | grep node-exporter | awk '{print $1}')
PROM_RELOADER_ID=$(docker ps -a | grep prometheus_reloader | awk '{print $1}')
# Throw Banner
echo "############################################################"
echo "# Synology Install Prometheus Stack Tool v${VERSION}"
echo "############################################################"
# Always cd so we're not in a workdir
cd /volume1/docker
# Delete Docker Containers
echo; echo ">>>>>> Cleaning containers"
container_id=( ${ALERTMANAGER_ID} ${PROMETHEUS_ID} ${GRAFANA_ID} ${NODE_EXPORTER_ID} ${PROM_RELOADER_ID} )
for i in "${container_id[@]}"; do
DNAME=$(docker ps -af "id=${i}" | awk '!/NAME/ {print $NF}')
echo "Removing docker container id ${i} and name ${DNAME}"
docker rm -f ${i} > /dev/null 2>&1
done
# Cleanup Filesystem
echo; echo ">>>>>> Cleaning filesystem"
clean_filesystem=( ${PROMETHEUS_ROOT} ${ALERTMANAGER_ROOT} ${GRAFANA_ROOT} )
for i in "${clean_filesystem[@]}"; do
if [[ -d ${i} ]]; then
rm -rf ${i}
if [[ $? -eq 0 ]]; then
echo "Deleted folder ${i}"
elif [[ $? -ne 0 ]]; then
echo "Could not delete folder ${i}. Error code was $?"
exit 1
fi
fi
done
rm -rf ${DOCKER_VOLUME}/docker-compose.yml
# Finish
echo; echo ">>>>>> Uninstall complete"