-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigscript.sh
49 lines (48 loc) · 1.57 KB
/
configscript.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
#!/bin/bash
set -ex
curl https://binaries.cockroachdb.com/cockroach-latest.linux-amd64.tgz > cockroach.tgz
tar xfz cockroach.tgz
cp -i cockroach-latest.linux-amd64/cockroach /usr/local/bin
cockroach version
myip=$(curl -s -m 100 http://169.254.169.254/2009-04-04/meta-data/local-ipv4)
leader=$(curl -k -m 100 $thisisaclientscheme://$myip:$thisisaclientport/v2/stats/leader | jq -r '.[]')
if [ "$leader" = 'not current leader' ]; then
leaderid=$(curl -k -m 100 $thisisaclientscheme://$myip:$thisisaclientport/v2/stats/self | jq '.leaderInfo.leader')
leaderip=$(curl -k -m 100 $thisisaclientscheme://$myip:$thisisaclientport/v2/members | jq -r ".members[] | select(.id == $leaderid) | .name")
while [ -z $connected ]; do
set +e
cockroach node ls --insecure --host $leaderip
if [ $? -eq 0 ]; then
set -e
echo joining cluster, exiting
x=1
while [ $x -ne 0 ]; do
set +e
cockroach start --advertise-host $myip --background --insecure --join=$leaderip
x=$?
set -e
if [ $x -ne 0 ]; then
sleep 5
else
connected='yes'
fi
done
else
set -e
echo failed to join cluster, waiting for leader to come up
sleep 5
fi
done
else
x=1
while [ $((x)) -gt 0 ]; do
set +e
cockroach start --insecure --advertise-host $myip --background
x=$?
set -e
if [ $((x)) -gt 0 ]; then
sleep 5
fi
done
fi
echo connected