This repository was archived by the owner on Oct 5, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathstart_db_cluster.sh
executable file
·88 lines (68 loc) · 3.61 KB
/
start_db_cluster.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
86
87
88
#!/bin/bash
# USAGE:
# export ARANGO_LICENSE_KEY=<arangodb-enterprise-license>
# ./start_db_cluster.sh <dockerImage>
# EXAMPLE:
# ./start_db_cluster.sh docker.io/arangodb/arangodb:3.7.1
docker pull "$1"
LOCATION=$(pwd)/$(dirname "$0")
docker network create arangodb --subnet 172.28.0.0/16
echo"Averysecretword">"$LOCATION"/jwtSecret
docker run --rm -v "$LOCATION"/jwtSecret:/jwtSecret "$1" arangodb auth header --auth.jwt-secret /jwtSecret >"$LOCATION"/jwtHeader
AUTHORIZATION_HEADER=$(cat "$LOCATION"/jwtHeader)
echo"Starting containers..."
docker run -d -v "$LOCATION"/jwtSecret:/jwtSecret -e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" --network arangodb --ip 172.28.1.1 --name agent1 "$1" arangodb --cluster.start-dbserver false --cluster.start-coordinator false --auth.jwt-secret /jwtSecret
docker run -d -v "$LOCATION"/jwtSecret:/jwtSecret -e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" --network arangodb --ip 172.28.1.2 --name agent2 "$1" arangodb --cluster.start-dbserver false --cluster.start-coordinator false --starter.join agent1 --auth.jwt-secret /jwtSecret
docker run -d -v "$LOCATION"/jwtSecret:/jwtSecret -e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" --network arangodb --ip 172.28.1.3 --name agent3 "$1" arangodb --cluster.start-dbserver false --cluster.start-coordinator false --starter.join agent1 --auth.jwt-secret /jwtSecret
docker run -d -v "$LOCATION"/jwtSecret:/jwtSecret -e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" --network arangodb --ip 172.28.2.1 --name dbserver1 "$1" arangodb --cluster.start-dbserver true --cluster.start-coordinator false --starter.join agent1 --auth.jwt-secret /jwtSecret
docker run -d -v "$LOCATION"/jwtSecret:/jwtSecret -e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" --network arangodb --ip 172.28.2.2 --name dbserver2 "$1" arangodb --cluster.start-dbserver true --cluster.start-coordinator false --starter.join agent1 --auth.jwt-secret /jwtSecret
docker run -d -v "$LOCATION"/jwtSecret:/jwtSecret -e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" --network arangodb --ip 172.28.3.1 --name coordinator1 "$1" arangodb --cluster.start-dbserver false --cluster.start-coordinator true --starter.join agent1 --auth.jwt-secret /jwtSecret
docker run -d -v "$LOCATION"/jwtSecret:/jwtSecret -e ARANGO_LICENSE_KEY="$ARANGO_LICENSE_KEY" --network arangodb --ip 172.28.3.2 --name coordinator2 "$1" arangodb --cluster.start-dbserver false --cluster.start-coordinator true --starter.join agent1 --auth.jwt-secret /jwtSecret
debug_container() {
if [ !"$(docker ps -aqf name="$1")" ];then
echo"$1 container not found!"
exit 1
fi
running=$(docker inspect -f '{{.State.Running}}'"$1")
if [ "$running"=false ]
then
echo"$1 is not running!"
echo"---"
docker logs "$1"
echo"---"
exit 1
fi
}
debug() {
forcin agent1 \
agent2 \
agent3 \
dbserver1 \
dbserver2 \
coordinator1 \
coordinator2 ;do
debug_container $c
done
}
wait_server() {
# shellcheck disable=SC2091
until$(curl --output /dev/null --silent --head --fail -i -H "$AUTHORIZATION_HEADER""http://$1/_api/version");do
printf'.'
debug
sleep 1
done
}
echo"Waiting..."
# Wait for agents:
forain 172.28.1.1:8531 \
172.28.1.2:8531 \
172.28.1.3:8531 \
172.28.2.1:8530 \
172.28.2.2:8530 \
172.28.3.1:8529 \
172.28.3.2:8529 ;do
wait_server $a
done
docker exec coordinator1 arangosh --server.authentication=false --javascript.execute-string='require("org/arangodb/users").update("root", "test")'
#rm "$LOCATION"/jwtHeader "$LOCATION"/jwtSecret
echo"Done, your cluster is ready."