-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsul-server.bash
61 lines (48 loc) · 1.28 KB
/
consul-server.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# In User Data do:
# #!/bin/bash
# export ATLAS_USERNAME=...
# export ATLAS_TOKEN=...
# export CONSUL_VERSION=0.7.5
# curl https://raw.githubusercontent.com/calebdoxsey/cloud-machine/master/consul-server.bash | sudo -E /bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
if [ -z "${ATLAS_USERNAME}" ] ; then
echo "ATLAS_USERNAME is required"
exit 1
fi
if [ -z "${ATLAS_TOKEN}" ] ; then
echo "ATLAS_TOKEN is required"
exit 1
fi
if [ -z "${CONSUL_VERSION}" ] ; then
echo "CONSUL_VERSION is required"
exit 1
fi
apt-get install -y curl unzip
echo "[install] installing consul"
cd /tmp
curl -O -L https://releases.hashicorp.com/consul/$CONSUL_VERSION/consul_${CONSUL_VERSION}_linux_amd64.zip
unzip consul_${CONSUL_VERSION}_linux_amd64.zip
mv consul /usr/bin/consul
rm consul_${CONSUL_VERSION}_linux_amd64.zip
cat <<EOF > /etc/systemd/system/consul.service
[Unit]
Description=consul
[Service]
ExecStart=/usr/bin/consul agent -server \
-data-dir="/tmp/consul" \
-bootstrap-expect 3 \
-atlas=${ATLAS_USERNAME}/infrastructure \
-atlas-join \
-atlas-token="${ATLAS_TOKEN}"
Restart=always
[Install]
WantedBy=multi-user.target
EOF
echo "[install] starting consul"
systemctl daemon-reload
systemctl enable consul
systemctl start consul