github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/images/scripts/common/consul.sh (about) 1 #!/bin/sh -eux 2 3 # Install unzip since Consul is distributed as a zip 4 apt-get install -y unzip 5 6 # Download Consul 7 cd /tmp 8 wget https://releases.hashicorp.com/consul/0.6.0/consul_0.6.0_linux_amd64.zip -O consul.zip 9 10 # Install Consul 11 unzip consul.zip >/dev/null 12 rm consul.zip 13 chmod +x consul 14 mv consul /usr/local/bin/consul 15 mkdir -p /etc/consul.d 16 mkdir -p /mnt/consul 17 mkdir -p /etc/service 18 19 # Install the upstart service 20 cat >/etc/init/consul.conf <<EOF 21 description "Consul agent" 22 23 start on runlevel [2345] 24 stop on runlevel [!2345] 25 26 respawn 27 28 # This is to avoid Upstart re-spawning the process upon \`consul leave\` 29 normal exit 0 INT 30 31 # stop consul will not mark node as failed but left 32 kill signal INT 33 34 script 35 if [ -f "/etc/service/consul" ]; then 36 . /etc/service/consul 37 fi 38 39 # Make sure to use all our CPUs, because Consul can block a scheduler thread 40 export GOMAXPROCS=\`nproc\` 41 42 # Get the public IP 43 BIND=\`ifconfig eth0 | grep "inet addr" | awk '{ print substr(\$2,6) }'\` 44 45 exec /usr/local/bin/consul agent \\ 46 -config-dir="/etc/consul.d" \\ 47 -bind=\$BIND \\ 48 \${CONSUL_FLAGS} \\ 49 >>/var/log/consul.log 2>&1 50 end script 51 EOF 52 53 # Install dnsmasq 54 apt-get install -y dnsmasq 55 echo "server=/consul/127.0.0.1#8600" > /etc/dnsmasq.d/10-consul 56 /etc/init.d/dnsmasq restart