forked from pingles/consul-coreos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
etcd-bootstrap
executable file
·33 lines (23 loc) · 936 Bytes
/
etcd-bootstrap
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
#!/bin/bash
set -e
this_ip="$1"; shift
this_machine="$1"; shift
consul_args="$@"
etcdctl="docker run --net=host --rm cap10morgan/etcdctl:0.4.6"
conntrack="docker run --net=host --privileged --rm cap10morgan/conntrack"
function leave-cluster {
${etcdctl} rm /consul.io/bootstrap/machines/${this_machine} || true
consul leave || true
# work around a Docker / Consul interaction bug that makes quickly-restarted containers not sync
${conntrack} -F
}
trap leave-cluster EXIT
${etcdctl} ls /consul.io/bootstrap/machines || ${etcdctl} mkdir /consul.io/bootstrap/machines
nodes=( $(${etcdctl} ls /consul.io/bootstrap/machines) )
if [[ ${#nodes[@]} > 0 ]]; then
first_node=${nodes[0]}
join_ip=$(${etcdctl} get ${first_node})
join_arg="--join ${join_ip}"
fi
${etcdctl} set /consul.io/bootstrap/machines/${this_machine} ${this_ip} > /dev/null
/bin/start --server --bootstrap-expect 3 --advertise ${this_ip} ${join_arg} $@