-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinst_consul.sh
87 lines (72 loc) · 2.17 KB
/
inst_consul.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
STEP00=`sudo apt install unzip -y`
echo "Install Unzip"
sleep 1
echo $STEP00
CONSUL_VERSION="1.5.1"
STEP01=`curl --silent --remote-name https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip`
echo "Donwloading latest CONSUL"
echo $STEP01
echo "Finished"
sleep 1
echo "Unzip CONSUL"
STEP02=`unzip consul_${CONSUL_VERSION}_linux_amd64.zip`
echo $STEP02
echo `ls -al consul`
sleep 1
echo "Change the owner of consul to root"
STEP03=`sudo chown root:root consul`
echo $STEP03
sleep 1
echo "copy consul to /usr/local/bin"
STEP04=`sudo mv consul /usr/local/bin/`
echo $STEP04
sleep 1
echo "Verifying consul Version"
STEP05=`consul --version`
echo $STEP05
sleep 1
echo "Performming Vault autocomplete install"
STEP06=`consul -autocomplete-install`
echo $STEP06
complete -C /usr/local/bin/consul consul
sleep 1
echo "Create a unique, non-privileged system user to run Consul and create its data directory"
STEP07_1=`sudo useradd --system --home /usr/local/etc/consul --shell /bin/false consul`
echo $STEP07_1
STEP07_2=`sudo mkdir --parents /var/run/consul`
echo $STEP07_2
STEP07_3=`sudo chown --recursive consul:consul /var/run/consul`
echo $STEP07_3
sleep 1
echo "Configure systemd: Create a Consul Service file"
sudo touch /etc/systemd/system/consul.service
sudo cat << EOF > /etc/systemd/system/consul.service
### BEGIN INIT INFO
# Provides: consul
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Consul agent
# Description: Consul service discovery framework
### END INIT INFO
[Unit]
Description=Consul server agent
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/usr/local/etc/consul/server_agent.json
[Service]
User=consul
Group=consul
PIDFile=/var/run/consul/consul.pid
PermissionsStartOnly=true
ExecStart=/usr/local/bin/consul agent -config-file=/usr/local/etc/consul/server_agent.json -pid-file=/var/run/consul/consul.pid -disable-keyring-file
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
EOF