Skip to content

Instantly share code, notes, and snippets.

@mhamrah
Created April 10, 2015 01:29
Show Gist options
  • Save mhamrah/1edf4121316b583d780f to your computer and use it in GitHub Desktop.
Save mhamrah/1edf4121316b583d780f to your computer and use it in GitHub Desktop.
scale-fleet
#!/bin/bash
FLEET_HOST=http://gotham.gettyimages.io:8080
SERVICE=$1
DESIRED_SIZE=$2
INSTANCES=($(curl -s $FLEET_HOST/fleet/v1/units | jq ".units[].name | select(startswith(\"$SERVICE@\"))" | grep '\w@\d\.service'))
CURRENT_SIZE=${#INSTANCES[@]}
echo "Current instance count for $service is: $CURRENT_SIZE"
if [[ $DESIRED_SIZE = $CURRENT_SIZE ]]; then
echo "doing nothing, current size is equal desired size"
elif [[ $DESIRED_SIZE < $CURRENT_SIZE ]]; then
echo "going to scale down instance $CURRENT_SIZE"
until [[ $DESIRED_SIZE = $CURRENT_SIZE ]]; do
curl -X DELETE $FLEET_HOST/fleet/v1/units/${SERVICE}@${CURRENT_SIZE}.service
let CURRENT_SIZE=CURRENT_SIZE-1
done
echo "new instance count is $CURRENT_SIZE"
else
echo "going to scale up to $DESIRED_SIZE"
payload=`curl -s $FLEET_HOST/fleet/v1/units/${SERVICE}@.service | jq '. | { "desiredState":"launched", "options": .options }'`
until [[ $DESIRED_SIZE = $CURRENT_SIZE ]]; do
let CURRENT_SIZE=CURRENT_SIZE+1
curl -X PUT -d "${payload}" -H 'Content-Type: application/json' $FLEET_HOST/fleet/v1/units/$SERVICE@${CURRENT_SIZE}.service
done
echo "new instance count is $CURRENT_SIZE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment