Skip to content

Instantly share code, notes, and snippets.

@bluk
Last active August 24, 2016 13:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bluk/a94551f54863e96ee78e to your computer and use it in GitHub Desktop.
Save bluk/a94551f54863e96ee78e to your computer and use it in GitHub Desktop.
Consul Bootstrap on CoreOS
#!/bin/bash
# From https://gist.github.com/philips/56fa3f5dae9060fbd100
source /etc/environment
name=$(cat /etc/machine-id)
if [ ! -f /opt/consul ]; then
mkdir /opt
mkdir /var/lib/consul
cd /tmp
wget https://dl.bintray.com/mitchellh/consul/0.4.0_linux_amd64.zip
unzip 0.4.0_linux_amd64.zip
mv consul /opt/consul
chmod +x /opt/consul
wget https://gist.githubusercontent.com/bluk/76911335faf4008c18ed/raw/2169ad1b886e929802387229bd3159a742ae7c69/consul-config.json
mv consul-config.json /opt/consul-config.json
fi
FLAGS="-help "
if etcdctl mk /consul.io/bootstrap/started true; then
flags="${flags} -bootstrap"
else
echo "This cluster has already been bootstrapped"
fi
etcdctl set /consul.io/bootstrap/machines/${name} ${COREOS_PRIVATE_IPV4}
flags=$(etcdctl ls /consul.io/bootstrap/machines | while read line; do
ip=$(etcdctl get ${line})
echo ${flags} -join ${ip}
done)
flags="${flags} -config-file /opt/consul-config.json"
echo ${flags}
/opt/consul agent -data-dir /var/lib/consul -server ${flags}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment