open-consul/terraform/aws/scripts/install.sh
Mike Cowgill fd8772f442 Update quick start AWS Terraform
This change started out as a quick update to RHEL 7 support (aka systemd), in
the process I realized most of the other platforms could use an update. While
trying to cleanup there I discovered I was repeating of bunch of information
that might be better maintained in one place - as a result:
 * consolidated server.sh and install.sh
 * removed upstart-join.conf in a favor of join flag in the consul start
 * removed platform specific folders and increased complexity of install.sh to
   include handling the differences
 * updated and extracted consul version
 * added a consistent ip_table.sh file to open ports on firewalls
 * updating consul service management configurations to enable proper restarting behavior for each platform
 * the configuration naming convention is <distro_origin>_file_name
 * added platform to the security group name so you can easily launch multpile platforms at once
 * fixes #1304
2016-03-10 06:22:24 -08:00

54 lines
1.5 KiB
Bash

#!/bin/bash
set -e
echo "Installing dependencies..."
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update -y
sudo apt-get install -y unzip
else
sudo yum update -y
sudo yum install -y unzip wget
fi
echo "Fetching Consul..."
CONSUL=0.6.3
cd /tmp
wget https://releases.hashicorp.com/consul/${CONSUL}/consul_${CONSUL}_linux_amd64.zip -O consul.zip
echo "Installing Consul..."
unzip consul.zip >/dev/null
chmod +x consul
sudo mv consul /usr/local/bin/consul
sudo mkdir -p /opt/consul/data
# Read from the file we created
SERVER_COUNT=$(cat /tmp/consul-server-count | tr -d '\n')
CONSUL_JOIN=$(cat /tmp/consul-server-addr | tr -d '\n')
# Write the flags to a temporary file
cat >/tmp/consul_flags << EOF
CONSUL_FLAGS="-server -bootstrap-expect=${SERVER_COUNT} -join=${CONSUL_JOIN} -data-dir=/opt/consul/data"
EOF
if [ -f /tmp/upstart.conf ];
then
echo "Installing Upstart service..."
sudo mkdir -p /etc/consul.d
sudo mkdir -p /etc/service
sudo chown root:root /tmp/upstart.conf
sudo mv /tmp/upstart.conf /etc/init/consul.conf
sudo chmod 0644 /etc/init/consul.conf
sudo mv /tmp/consul_flags /etc/service/consul
sudo chmod 0644 /etc/service/consul
else
echo "Installing Systemd service..."
sudo mkdir -p /etc/systemd/system/consul.d
sudo chown root:root /tmp/consul.service
sudo mv /tmp/consul.service /etc/systemd/system/consul.service
sudo chmod 0644 /etc/systemd/system/consul.service
sudo mv /tmp/consul_flags /etc/sysconfig/consul
sudo chown root:root /etc/sysconfig/consul
sudo chmod 0644 /etc/sysconfig/consul
fi