1#!/bin/bash
2# SOURCE: GRUNTWORKS
3# This script is meant to be run in the User Data of each EC2 Instance while it's booting. The script uses the
4# run-consul script to configure and start Consul in server mode. Note that this script assumes it's running in an AMI
5# built from the Packer template in examples/consul-ami/consul.json.
6
7set -e
8
9# Send the log output from this script to user-data.log, syslog, and the console
10# From: https://alestic.com/2010/12/ec2-user-data-output/
11exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
12
13# Install Consul
14if [[ -n "${consul_download_url}" ]]; then
15    /home/ubuntu/scripts/install-consul --download-url "${consul_download_url}"
16else
17    /home/ubuntu/scripts/install-consul --version "${consul_version}"
18fi
19
20# Update User:Group on this file really quick
21chown consul:consul /opt/consul/config/telemetry.json
22
23# These variables are passed in via Terraform template interplation
24/opt/consul/bin/run-consul --server --cluster-tag-key "${cluster_tag_key}" --cluster-tag-value "${cluster_tag_value}"
25