-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-cluster.sh
executable file
·62 lines (57 loc) · 2.69 KB
/
start-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
#!/bin/bash
Green='\033[0;32m'
Yellow='\033[1;33m'
Red='\033[0;31m'
Color_Off='\033[0m'
Cluster=${1:-v}
# Change this to env flag
Dont_Init_Flag=$2
if ! docker network inspect vaulty-net > /dev/null; then
# TODO IF VAULTY_NET DOESN"T EXISTS THEN CREATE IT
echo -e ${Red}You must create the network for vaulty first. Try running: \"docker network create vaulty-net --subnet 192.168.211.0/24\"${Color_Off}
else
if ! docker-compose -p $Cluster -f /Users/maxwinslow/dev/vlty/$Cluster/docker-compose.yml up -d; then
echo -e ${Red}docker-compose up step failed or was cancelled. Check the docker-compose.yml file.${Color_Off}
else
if [[ "$Dont_Init_Flag" = "ni" ]]; then
echo -e ${Yellow}The \"noinit\" argument was passed \'ni\'.${Color_Off}
echo -e ${Green}The Vault containers are running${Color_Off}${Yellow} but vault was not initialized.${Color_Off}
elif [[ $# -eq 2 && $Dont_Init_Flag!=ni ]]; then
echo -e ${Yellow}The argument passed to ./start-cluster wasn\'t recognized. Only \'ni\' is accepted.${Color_Off}
docker-compose -p v down
echo -e ${Yellow}Please try again.${Color_Off}
exit 1
else
if [ "$Cluster" = "v" ]; then
nodeport1=8200
nodeport2=8202
nodeport3=8204
elif [ "$Cluster" = "dr" ]; then
nodeport1=8206
nodeport2=8208
nodeport3=8210
elif [ "$Cluster" = "pr" ]; then
nodeport1=8212
nodeport2=8214
nodeport3=8216
else
echo "Unknown cluster: $Cluster"
exit 1
fi
sleep 5
echo -e ${Yellow}Initializing $Cluster cluster${Color_Off}
VAULT_ADDR=http://127.0.0.1:$nodeport1 vault operator init -format=json -key-shares=1 -key-threshold=1 | jq -r > /Users/maxwinslow/dev/vlty/$Cluster/init.json
echo -e ${Green}Cluster initialized. Init output saved to /Users/maxwinslow/dev/vlty/$Cluster/init.json${Color_Off}
echo -e ${Yellow}Unsealing vault.${Color_Off}
VAULT_ADDR=http://127.0.0.1:$nodeport1 vault operator unseal $(cat /Users/maxwinslow/dev/vlty/$Cluster/init.json| jq -r '.unseal_keys_b64[]')
echo -e ${Green}Cluster unsealed.${Color_Off}
echo -e ${Yellow}Logging in with root token.${Color_Off}
VAULT_ADDR=http://127.0.0.1:$nodeport1 vault login $(cat /Users/maxwinslow/dev/vlty/$Cluster/init.json| jq -r '.root_token')
echo -e ${Yellow}Unsealing standby nodes${Color_Off}
sleep 2
VAULT_ADDR=http://127.0.0.1:$nodeport2 vault operator unseal $(cat /Users/maxwinslow/dev/vlty/$Cluster/init.json| jq -r '.unseal_keys_b64[]')
VAULT_ADDR=http://127.0.0.1:$nodeport3 vault operator unseal $(cat /Users/maxwinslow/dev/vlty/$Cluster/init.json| jq -r '.unseal_keys_b64[]')
watch VAULT_ADDR=http://127.0.0.1:$nodeport1 vault operator members
fi
fi
fi