Skip to content

Instantly share code, notes, and snippets.

@willscripted
Created March 11, 2016 14:26
Show Gist options
  • Save willscripted/2d625ba1ea092be0c129 to your computer and use it in GitHub Desktop.
Save willscripted/2d625ba1ea092be0c129 to your computer and use it in GitHub Desktop.
Bootstrap consul on top of etcd
#!/usr/bin/env bash
source /etc/environment
# If I am able to contact etcd2
/usr/bin/etcdctl mkdir /consul/leader
if [[ $? -eq 0 ]]; then
echo "Master lock created, bootstrapping"
/bin/bash -c "/usr/bin/docker run \
--net=host gliderlabs/consul-server:0.6 \
-server \
-bootstrap \
-advertise $COREOS_PRIVATE_IPV4"
else
echo "Could not create master lock, assume follower"
joins="$(/usr/bin/etcdctl members list \
| etcdctl member list \
| awk '{ print $3 }' \
| sed 's/peerURLs=//g' \
| sed 's/,\?http:\/\//-retry-join /g' \
| sed 's/:2380/ \\/g')"
/bin/bash -c "/usr/bin/docker run \
--net=host gliderlabs/consul-server:0.6 \
-server \
$joins
-advertise $COREOS_PRIVATE_IPV4"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment