Skip to content

Instantly share code, notes, and snippets.

@nazarii-piontko
Last active August 20, 2018 17:18
Show Gist options
  • Save nazarii-piontko/41b37dca9d20312501c2ce4753a2a476 to your computer and use it in GitHub Desktop.
Save nazarii-piontko/41b37dca9d20312501c2ce4753a2a476 to your computer and use it in GitHub Desktop.
Consul 1.2.2 install script for Ubuntu
#!/bin/bash
# Consul 1.2.2 install script for Ubuntu.
# It downloads consul 1.2.2 and installs as daemon with default dummy configuration.
# https://www.consul.io
CONFIG='{
"server": true,
"bootstrap": true,
"data_dir": "/var/consul"
}'
CONSUL_URL=https://releases.hashicorp.com/consul/1.2.2/consul_1.2.2_linux_amd64.zip
set -e
# Install required utils
apt-get update -y
apt-get install -y wget unzip
# Download and install copy
wget -O consul.zip ${CONSUL_URL}
unzip consul.zip
rm consul.zip
mv consul /usr/bin/
chmod +x /usr/bin/consul
# Create directories
mkdir -p /etc/consul
mkdir -p /var/consul
# Make configuration
cat > /etc/consul/consul.json << EOF
${CONFIG}
EOF
# Register as daemon
cat > /etc/systemd/system/consul.service << EOF
[Unit]
Description=Consul Agent
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=on-failure
ExecStart=/usr/bin/consul agent -config-dir=/etc/consul
ExecReload=/bin/kill -SIGHUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
EOF
systemctl enable consul
systemctl start consul
systemctl status consul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment