2020-10-06 01:16:09 +00:00
|
|
|
#!/bin/bash
|
2023-03-28 22:48:58 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-10-06 01:16:09 +00:00
|
|
|
# SOURCE: GRUNTWORKS
|
|
|
|
# This script is meant to be run in the User Data of each EC2 Instance while it's booting. The script uses the
|
|
|
|
# run-consul script to configure and start Consul in client mode. Note that this script assumes it's running in an AMI
|
|
|
|
# built from the Packer template in examples/consul-ami/consul.json.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-12-11 19:11:14 +00:00
|
|
|
|
2020-10-06 01:16:09 +00:00
|
|
|
# Send the log output from this script to user-data.log, syslog, and the console
|
|
|
|
# From: https://alestic.com/2010/12/ec2-user-data-output/
|
|
|
|
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
|
|
|
|
|
2020-12-11 19:11:14 +00:00
|
|
|
# Install Consul
|
|
|
|
if [[ -n "${consul_download_url}" ]]; then
|
|
|
|
/home/ubuntu/scripts/install-consul --download-url "${consul_download_url}"
|
|
|
|
else
|
|
|
|
/home/ubuntu/scripts/install-consul --version "${consul_version}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update User:Group on this file really quick
|
|
|
|
chown consul:consul /opt/consul/config/telemetry.json
|
|
|
|
|
2020-10-06 01:16:09 +00:00
|
|
|
# These variables are passed in via Terraform template interplation
|
|
|
|
/opt/consul/bin/run-consul --client --cluster-tag-key "${cluster_tag_key}" --cluster-tag-value "${cluster_tag_value}"
|