-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdocker.sh
executable file
·86 lines (78 loc) · 2.8 KB
/
docker.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
SUDO=""
PWD=`pwd`
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root, it will try 'sudo' when needed."
SUDO="sudo"
fi
case $1 in
start)
echo "Starting containers..."
cd $PWD/tools/docker
if [ ! -f prometheus.yml ]; then
# use the template as default config, to start Prometheus process
cp configs/prometheus.yml.template prometheus.yml
fi
$SUDO docker-compose up -d
# if datasource "test-cluster" doesn't exist, this is a new Grafana instahce,
# and we'll going to initial its configs
echo "Wait 30s for Grafana to finish startup..."
sleep 30 # wail Grafana to startup
DATASOURCE=$(curl -s -H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
'http://localhost:3000/api/datasources/id/test-cluster')
if [[ $DATASOURCE = *"Data source not found"* ]]; then
echo "Initializing Grafana configuration..."
# add datasource
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-H "Authorization: Basic YWRtaW46YWRtaW4=" -XPOST \
-d '{
"name": "test-cluster",
"type": "prometheus",
"access": "proxy",
"url": "http://prometheus:9090",
"basicAuth": false,
"withCredentials": false,
"isDefault": true,
"jsonData": {
"httpMethod": "GET",
"keepCookies": [
]
},
"readOnly": true
}' \
"http://localhost:3000/api/datasources"
# import dashboards
cd configs
./grafana-config-copy.py
else
echo "Using existing Grafana datasource $DATASOURCE"
fi
cd $PWD
;;
reload)
echo "Reloading Prometheus..."
$SUDO docker exec prometheus kill -HUP 1
;;
stop)
echo "Stopping containers..."
cd $PWD/tools/docker
$SUDO docker-compose down
cd $PWD
;;
clean)
echo "Stopping containers..."
cd $PWD/tools/docker
$SUDO docker-compose down
echo "Deleting all containers and data..."
$SUDO rm -rf data
;;
*)
echo "Setting InfluxDB database name to $1..."
sed "s/<DBNAME>/$1/g" $PWD/tools/docker/configs/prometheus.yml.template \
> $PWD/tools/docker/prometheus.yml
$SUDO docker exec prometheus kill -HUP 1
;;
esac
exit 0;