-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-elk-stack.sh
executable file
·61 lines (48 loc) · 1.31 KB
/
start-elk-stack.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
#!/bin/bash
export CLIENT_DIAG_PATH=$1
source ./.env
check_kibana_status() {
for i in {1..30}; do
kibana_status=`curl -sL -w "%{http_code}\\n" "http://localhost:5601/status" -o /dev/null`
if [ $kibana_status == "200" ]; then
echo ""
break
else
if [ ${i} == "30" ]; then
kibana_timeout
fi
sleep 2
printf "."
fi
done
}
import_kibana_dashboards() {
for f in ./kibana/dashboards/*.json
do
curl -X POST "http://127.0.0.1:5601/api/kibana/dashboards/import" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d @"$f" -s -o /dev/null
done
}
kibana_timeout() {
echo ""
echo "Timed out while waiting for Kibana to initialize."
echo "Try rerunning the script"
exit 1
}
echo "Starting containers"
docker-compose up -d
sleep 3
# elasticsearch files are created by dockerd (root) but the container runs as current user
# So fix perms and restart any containers not running
sudo chown -R `whoami`:`whoami` $CLIENT_DIAG_PATH
sudo chmod -R 777 $CLIENT_DIAG_PATH
docker-compose up -d
echo "Waiting for Kibana"
check_kibana_status
echo "Importing dashboards"
import_kibana_dashboards
echo "containers status"
docker-compose ps
echo ""
echo ""
echo "Visit http://<ip address>:5601 to use Kibana"
echo "Rerun the script if there's any containers not running."