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
|
|
|
|
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..."
|
2016-05-04 16:03:39 +00:00
|
|
|
CONSUL=0.6.4
|
2016-01-19 01:12:48 +00:00
|
|
|
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
|
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..."
|
|
|
|
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
|
|
|
|
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
|