Skip to content

Instantly share code, notes, and snippets.

@vdvm
Created November 3, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vdvm/caa9f7063a53c68555b0 to your computer and use it in GitHub Desktop.
Save vdvm/caa9f7063a53c68555b0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
if [[ -e /home/core/volumes/consul/raft/peers.json ]] && [[ $(cat /home/core/volumes/consul/raft/peers.json | jq '. | length') -ge 3 ]]; then
echo "CONSUL_BOOTSTRAP=\"\"" > /tmp/consul-env
exit
fi
if [[ MACHINES=$(etcdctl ls /consul.io/machines | grep -v ${HOSTNAME}) ]] && [[ ${#MACHINES[@]} -ge 1 ]]; then
for MACHINE in "$MACHINES"; do
IP=$(etcdctl get /consul.io/machines/${MACHINE})
echo "CONSUL_BOOTSTRAP=\"-join ${IP}\"" > /tmp/consul-env
exit
done
fi
echo "CONSUL_BOOTSTRAP=\"-bootstrap\"" > /tmp/consul-env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment