Last active
August 29, 2015 14:17
-
-
Save lrvick/4910579b160936c01aa9 to your computer and use it in GitHub Desktop.
Rolling CoreOS fleet restart
This file contains hidden or 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
#!/bin/sh | |
SERVICE=$1 | |
BRANCH=$2 | |
HEALTH_URL=$3 | |
if [ -z "$HEALTH_URL" ]; then | |
echo "Syntax: roll-restart someservice somebranch http://localhost:80" | |
exit | |
fi | |
MACHINE_IPS=$(fleetctl list-machines | grep ${SERVICE}-${BRANCH} | awk '{print $2}'); | |
for IP in $MACHINE_IPS; do | |
echo "$SERVICE | $BRANCH | $IP -> Connecting" | |
ssh -A core@${IP} 'bash -s' << EOF | |
echo "$SERVICE | $BRANCH | $IP -> Removing from ELB" | |
sudo systemctl stop ${SERVICE}-elb && sleep 30 | |
echo "$SERVICE | $BRANCH | $IP -> Restarting" | |
sudo systemctl restart ${SERVICE}@${BRANCH} | |
echo "$SERVICE | $BRANCH | $IP -> Waiting for $HEALTH_URL to respond" | |
until curl --output /dev/null --silent --head --fail ${HEALTH_URL}; do | |
echo "$SERVICE | $BRANCH | $IP -> ..." | |
sleep 5 | |
done | |
echo "$SERVICE | $BRANCH | $IP -> Adding back to ELB" | |
sudo systemctl start ${SERVICE}-elb | |
EOF | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment