Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generation of etcd dropins based on a list of ip addresses
#!/bin/bash
#
# usage: ./generate_etcd.sh 10.240.0.14 10.240.0.12 10.240.0.13
# output is in /tmp
for ipaddr in "$@"
do
let count+=1
peerlist="${peerlist},infra${count}=http://${ipaddr}:2380"
done
clustertoken="etcd-cluster-${RANDOM}"
let count=0
for ipaddr in "$@"
do
let count+=1
cat << EOF > /tmp/etcd2-config-${ipaddr}.sh
etcd2 -name infra${count} -initial-advertise-peer-urls http://${ipaddr}:2380 \
-listen-peer-urls http://${ipaddr}:2380 \
-listen-client-urls http://${ipaddr}:2379,http://127.0.0.1:2379 \
-advertise-client-urls http://${ipaddr}:2379 \
-initial-cluster-token $clustertoken \
-initial-cluster ${peerlist:1} \
-data-dir /var/lib/etcd2 \
-initial-cluster-state new
EOF
cat << EOF > /tmp/10-config-${ipaddr}.conf
[Service]
Environment=ETCD_NAME=infra${count}
Environment=ETCD_INITIAL_ADVERTISE_PEER_URLS=http://${ipaddr}:2380
Environment=ETCD_LISTEN_PEER_URLS=http://${ipaddr}:2380
Environment=ETCD_LISTEN_CLIENT_URLS=http://${ipaddr}:2379,http://127.0.0.1:2379
Environment=ETCD_ADVERTISE_CLIENT_URLS=http://${ipaddr}:2379
Environment=ETCD_INITIAL_CLUSTER_TOKEN=$clustertoken
Environment=ETCD_INITIAL_CLUSTER=${peerlist:1}
Environment=ETCD_DATA_DIR=/var/lib/etcd2
Environment=ETCD_INITIAL_CLUSTER_STATE=new
EOF
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment