github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/foundation/consul/data/common/app-dev/main.sh.tpl (about) 1 #!/bin/bash 2 set -e 3 4 oe() { $@ 2>&1 | logger -t otto > /dev/null; } 5 ol() { echo "[otto] $@"; } 6 7 dir=$(pwd) 8 9 # Download and setup Consul directories 10 if ! command -v consul >/dev/null 2>&1; then 11 ol "Installing Consul..." 12 oe sudo apt-get update -y 13 oe sudo apt-get install -y unzip 14 cd /tmp 15 oe wget https://releases.hashicorp.com/consul/0.6.0/consul_0.6.0_linux_amd64.zip -O consul.zip 16 oe unzip consul.zip 17 oe sudo chmod +x consul 18 oe sudo mv consul /usr/local/bin/consul 19 oe sudo mkdir -p /etc/consul.d 20 oe sudo mkdir -p /mnt/consul 21 oe sudo mkdir -p /etc/service 22 23 # Write the flags to a temporary file and move it into place 24 cat >/tmp/consul_flags << EOF 25 export CONSUL_FLAGS="-server -bootstrap -data-dir=/mnt/consul" 26 EOF 27 oe chmod 0644 /tmp/consul_flags 28 oe sudo mv /tmp/consul_flags /etc/service/consul 29 30 # Setup Consul service and start it 31 oe sudo cp ${dir}/upstart.conf /etc/init/consul.conf 32 33 # Setup DNS 34 ol "Installing dnsmasq for Consul..." 35 oe sudo apt-get install -y dnsmasq 36 echo "server=/consul/127.0.0.1#8600" > /tmp/dnsmasq 37 oe sudo mv /tmp/dnsmasq /etc/dnsmasq.d/10-consul 38 oe sudo /etc/init.d/dnsmasq restart 39 fi 40 41 # Try to start consul 42 oe sudo start consul || true 43 44 # Write the service file 45 ol "Configuring consul service: {{ app_config.ServiceName }}" 46 cat <<DOC >/tmp/service.json 47 { 48 "service": { 49 "name": "{{ app_config.ServiceName }}", 50 "tags": [], 51 "port": {{ app_config.ServicePort }} 52 } 53 } 54 DOC 55 oe chmod 0644 /tmp/service.json 56 oe sudo mv /tmp/service.json /etc/consul.d/service.{{ app_config.ServiceName }}.json 57 58 # Reload consul. It is okay if this fails. 59 oe consul reload