-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetcd-install.sh
executable file
·75 lines (63 loc) · 2.2 KB
/
etcd-install.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
#!/bin/bash
set -e
# Advertised IP address of this node
export ADVERTISE_IP=10.0.0.1
# List of etcd servers (nodename=https://ip:port), comma separated
export ETCD_ENDPOINTS="con0=https://10.0.0.1:2380,con1=https://10.0.0.2:2380,con2=https://10.0.0.3:2380"
# Specify the version (vX.Y.Z) of etcd assets to deploy
export ETCD_VER=v3.1.5
function init_config {
local REQUIRED=( 'ADVERTISE_IP' 'ETCD_ENDPOINTS' 'ETCD_VER' )
if [ -z $ADVERTISE_IP ]; then
export ADVERTISE_IP=$(awk -F= '/COREOS_PUBLIC_IPV4/ {print $2}' /etc/environment)
fi
for REQ in "${REQUIRED[@]}"; do
if [ -z "$(eval echo \$$REQ)" ]; then
echo "Missing required config value: ${REQ}"
exit 1
fi
done
}
function init_templates {
local TEMPLATE=/etc/systemd/system/etcd-member.service.d/override.conf
if [ ! -f $TEMPLATE ]; then
echo "TEMPLATE: $TEMPLATE"
mkdir -p $(dirname $TEMPLATE)
cat << EOF > $TEMPLATE
[Service]
Environment="RKT_RUN_ARGS=\
--uuid-file-save=/var/lib/coreos/etcd-member-wrapper.uuid \\
--volume etcd-tls,kind=host,source=/etc/etcd/ssl \\
--mount volume=etcd-tls,target=/etc/etcd/ssl"
Environment="ETCD_IMAGE_TAG=${ETCD_VER}"
Environment="ETCD_NAME=$(hostname | egrep -o '^[^\.]+')"
Environment="ETCD_OPTS=--trusted-ca-file=/etc/etcd/ssl/ca.pem \\
--cert-file=/etc/etcd/ssl/peer.pem \\
--key-file=/etc/etcd/ssl/peer-key.pem \\
--client-cert-auth \\
--peer-trusted-ca-file=/etc/etcd/ssl/ca.pem \\
--peer-cert-file=/etc/etcd/ssl/peer.pem \\
--peer-key-file=/etc/etcd/ssl/peer-key.pem \\
--initial-advertise-peer-urls https://${ADVERTISE_IP}:2380 \\
--listen-peer-urls https://${ADVERTISE_IP}:2380 \\
--listen-client-urls https://${ADVERTISE_IP}:2379,http://127.0.0.1:2379 \\
--advertise-client-urls https://${ADVERTISE_IP}:2379 \\
--initial-cluster-token etcd-cluster-0 \\
--initial-cluster ${ETCD_ENDPOINTS} \\
--initial-cluster-state new"
EOF
fi
}
## Check config and generate templates
echo "+ Config etcd"
init_config
init_templates
echo
## Enable etcd-member.service
echo "+ Start etcd"
systemctl daemon-reload
systemctl enable etcd-member.service
systemctl start etcd-member.service
echo
## Finished!
echo "DONE"