Last active
October 24, 2015 11:57
-
-
Save ali-mosavian/7bedc2bfd72253bf73b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
instances=$(echo {0..2}) | |
public_ip=$(hostname -I | cut -d' ' -f1) | |
peers=$(for i in $instances; do echo "etcd.$i=http://${public_ip}:$((2380+$i*100))"; done | tr '\n' ',') | |
for i in $instances | |
do | |
docker stop etcd.$i > /dev/null 2>&1 || /bin/true | |
docker rm -f etcd.$i > /dev/null 2>&1 || /bin/true | |
done | |
for i in $instances | |
do | |
offset=$(($i*100)) | |
client_port=$((2379+$offset)) | |
peer_port=$((2380+$offset)) | |
docker run -d \ | |
-p $client_port:$client_port \ | |
-p $peer_port:$peer_port \ | |
--name etcd.$i \ | |
quay.io/coreos/etcd:v2.2.0 \ | |
-name etcd.$i \ | |
-advertise-client-urls http://$public_ip:$client_port \ | |
-listen-client-urls http://0.0.0.0:$client_port \ | |
-initial-advertise-peer-urls http://$public_ip:$peer_port \ | |
-listen-peer-urls http://0.0.0.0:$peer_port \ | |
-initial-cluster-token etcd-cluster-1 \ | |
-initial-cluster $peers \ | |
-initial-cluster-state new | |
done | |
client_peers=$(for i in $instances; do echo "http://${public_ip}:$((2379+$i*100))"; done | tr '\n' ',') | |
echo "Cluster started, peers: $client_peers" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment