Last active
August 29, 2015 14:20
-
-
Save willscripted/658b1d573a057c0d723a to your computer and use it in GitHub Desktop.
Bootstrap Consul on Docker via Cloudconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Inspired by Brandon Philips' consul bootstrap script | |
# https://gist.github.com/philips/56fa3f5dae9060fbd100 | |
source /etc/environment | |
num_expected_nodes=$1 | |
do_join() { | |
sleep 10 | |
docker exec consul /bin/consul join $@ | |
} | |
docker pull progrium/consul | |
name=$(/bin/cat /etc/machine-id) | |
/usr/bin/etcdctl set /consul.io/bootstrap/machines/${name} ${COREOS_PRIVATE_IPV4} | |
# Attempt to create bootstrap key | |
if etcdctl mk /consul.io/bootstrap/started true; then | |
export EXPECT=$num_expected_nodes | |
echo "expecting $EXPECT nodes to join bootstrap cluster" | |
$(docker run --rm progrium/consul cmd:run ${COREOS_PRIVATE_IPV4}) | |
else | |
ips=$(etcdctl ls /consul.io/bootstrap/machines | while read line; do | |
echo "$(etcdctl get ${line}) " | |
done) | |
ip=$(echo $ips | sed 's/\ .*//') | |
echo "This cluster has already been bootstrapped" | |
echo "Joining IPs: $ips" | |
do_join "$ips" & | |
$(docker run --rm progrium/consul cmd:run ${COREOS_PRIVATE_IPV4}::$ip) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment