Skip to content

Instantly share code, notes, and snippets.

@nabeken
Forked from dedene/bootstrap-consul
Last active August 29, 2015 14:11
Show Gist options
  • Save nabeken/31dc22e98b2151db6016 to your computer and use it in GitHub Desktop.
Save nabeken/31dc22e98b2151db6016 to your computer and use it in GitHub Desktop.
#!/bin/bash
CONSUL_VERSION=${CONSUL_VERSION:-0.4.1}
source /etc/environment
name=$(cat /etc/machine-id)
if [ ! -f /opt/consul ]; then
[ -d /opt ] || mkdir /opt
mkdir /var/lib/consul
wget -q -O- https://dl.bintray.com/mitchellh/consul/${CONSUL_VERSION}_linux_amd64.zip | funzip - > /opt/consul
chmod +x /opt/consul
fi
if etcdctl mk /consul.io/bootstrap/started true; then
flags="${flags} -bootstrap-expect 3"
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)
echo ${flags}
/opt/consul agent -data-dir /var/lib/consul -server ${flags}
#cloud-config
coreos:
etcd:
# generate a new token for each unique cluster from https://discovery.etcd.io/new
# WARNING: replace each time you 'vagrant destroy'
discovery: https://discovery.etcd.io/<insert-discovery-token>
addr: $public_ipv4:4001
peer-addr: $public_ipv4:7001
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
runtime: no
content: |
[Unit]
Description=fleet
[Service]
Environment=FLEET_PUBLIC_IP=$public_ipv4
ExecStart=/usr/bin/fleet
- name: consul.service
command: start
runtime: no
content: |
[Unit]
Description=consul
[Service]
ExecStartPre=-/usr/bin/mkdir /opt
ExecStartPre=-/usr/bin/wget --retry-connrefused -t 0 -nc -O /opt/bootstrap-consul https://gist.github.com/nabeken/31dc22e98b2151db6016/raw/b1fa98384d264658e8ef2d537dcda212ffa88266/bootstrap-consul
ExecStartPre=-/usr/bin/chmod +x /opt/bootstrap-consul
ExecStart=/opt/bootstrap-consul
[X-Fleet]
Global=true
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both
[Install]
WantedBy=sockets.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment