Skip to content

Instantly share code, notes, and snippets.

@JeanMertz
Forked from dedene/bootstrap-consul
Last active December 18, 2016 23:32
Show Gist options
  • Save JeanMertz/1365b3ce7a16ad7dca40 to your computer and use it in GitHub Desktop.
Save JeanMertz/1365b3ce7a16ad7dca40 to your computer and use it in GitHub Desktop.
#!/bin/bash
source /etc/environment
name=$(cat /etc/machine-id)
if [ ! -f /opt/consul ]; then
mkdir /opt
mkdir /var/lib/consul
wget https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip
unzip 0.4.1_linux_amd64.zip
mv consul /opt/consul
rm 0.4.1_linux_amd64.zip
chmod +x /opt/consul
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)
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.githubusercontent.com/dedene/36af9310a7e8e70f26a2/raw/f73b62fbe3d8c8294adc686be84b78bcdebd6e00/bootstrap-consul
ExecStartPre=-/usr/bin/chmod +x /opt/bootstrap-consul
ExecStart=/opt/bootstrap-consul
- 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