Skip to content

Instantly share code, notes, and snippets.

@bigblue
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigblue/f472de424cc37dabcba0 to your computer and use it in GitHub Desktop.
Save bigblue/f472de424cc37dabcba0 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Waits for all machines to have joined cluster
# then starts Weave router on leader, and passes leader
# ip address to all other Weave launches.
#
# Usage: ./weave_startup.sh [clusterSize]
#
clusterSize=$1
while true; do
numInCluster=$(fleetctl list-machines --no-legend | wc -l | tr -d '[[:space:]]')
if [ $numInCluster = $clusterSize ]; then
leaderId=$(etcdctl get /_coreos.com/fleet/lease/engine-leader | pcregrep -o1 '\"MachineID\":\"(.*)\",')
leaderIp=$(fleetctl list-machines --full | grep "$leaderId" | cut -f 2)
selfId=$(curl -Ls http://127.0.0.1:4001/v2/stats/self | pcregrep -o1 '\"name\":\"([^\"]*)\",')
echo "Leader: $leaderId, Self: $selfId"
if [ "$selfId" = "$leaderId" ]; then
echo "Starting weave router"
/opt/bin/weave launch
else
echo "Connecting to weave peer $leaderIp"
/opt/bin/weave launch $leaderIp
fi
break
else
echo "$numInCluster of $clusterSize machines connected. Waiting..."
fi;
sleep 5;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment