github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/builtin/foundation/consul/data/common/app-build/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  # Source the variables
    10  source ./vars
    11  
    12  # Download and setup Consul directories
    13  if ! command -v consul >/dev/null 2>&1; then
    14      ol "Installing Consul..."
    15      oe sudo apt-get update -y
    16      oe sudo apt-get install -y unzip
    17      cd /tmp
    18      oe wget https://releases.hashicorp.com/consul/0.6.0/consul_0.6.0_linux_amd64.zip -O consul.zip
    19      oe unzip consul.zip
    20      oe sudo chmod +x consul
    21      oe sudo mv consul /usr/local/bin/consul
    22      oe sudo mkdir -p /etc/consul.d
    23      oe sudo mkdir -p /mnt/consul
    24      oe sudo mkdir -p /etc/service
    25  
    26      # Write the flags to a temporary file and move it into place
    27      cat >/tmp/consul_flags << EOF
    28  export CONSUL_FLAGS="-data-dir=/mnt/consul -join=${consul_address}"
    29  EOF
    30      oe chmod 0644 /tmp/consul_flags
    31      oe sudo mv /tmp/consul_flags /etc/service/consul
    32  
    33      # Setup Consul service and start it
    34      oe sudo cp ${dir}/upstart.conf /etc/init/consul.conf
    35  
    36      # Setup DNS
    37      ol "Installing dnsmasq for Consul..."
    38      oe sudo apt-get install -y dnsmasq
    39      echo "server=/consul/127.0.0.1#8600" > /tmp/dnsmasq
    40      oe sudo mv /tmp/dnsmasq /etc/dnsmasq.d/10-consul
    41      oe sudo /etc/init.d/dnsmasq restart
    42  fi
    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