2016-03-11 13:59:08 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-01-19 01:12:48 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
echo "Installing dependencies..."
|
|
|
|
if [ -x "$(command -v apt-get)" ]; then
|
2017-10-17 23:59:34 +00:00
|
|
|
sudo su -s /bin/bash -c 'sleep 30 && apt-get update && apt-get install unzip' root
|
2016-01-19 01:12:48 +00:00
|
|
|
else
|
|
|
|
sudo yum update -y
|
|
|
|
sudo yum install -y unzip wget
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo "Fetching Consul..."
|
2017-10-18 17:08:25 +00:00
|
|
|
CONSUL=1.0.0
|
2016-01-19 01:12:48 +00:00
|
|
|
cd /tmp
|
2017-03-30 01:42:10 +00:00
|
|
|
wget https://releases.hashicorp.com/consul/${CONSUL}/consul_${CONSUL}_linux_amd64.zip -O consul.zip --quiet
|
2016-01-19 01:12:48 +00:00
|
|
|
|
|
|
|
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
|
2016-03-15 17:01:56 +00:00
|
|
|
sudo chown root:root /tmp/upstart.conf
|
2016-01-19 01:12:48 +00:00
|
|
|
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..."
|
2017-10-17 23:59:34 +00:00
|
|
|
sudo mkdir -p /etc/sysconfig
|
2016-01-19 01:12:48 +00:00
|
|
|
sudo mkdir -p /etc/systemd/system/consul.d
|
2016-03-15 17:01:56 +00:00
|
|
|
sudo chown root:root /tmp/consul.service
|
2016-01-19 01:12:48 +00:00
|
|
|
sudo mv /tmp/consul.service /etc/systemd/system/consul.service
|
2017-10-17 23:59:34 +00:00
|
|
|
sudo mv /tmp/consul*json /etc/systemd/system/consul.d/ || echo
|
2016-01-19 01:12:48 +00:00
|
|
|
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
|