Skip to content

Instantly share code, notes, and snippets.

@egbertp
Created May 13, 2015 09:06
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 egbertp/5542def7dbc98f0415ab to your computer and use it in GitHub Desktop.
Save egbertp/5542def7dbc98f0415ab to your computer and use it in GitHub Desktop.
Rebalance docker within fleet
#!/bin/bash -e
fleetctl list-units -fields=unit -no-legend | grep -v -e '@\|deis' | cut -d. -f1-2 | sort | uniq | while read name ; do
max=$(fleetctl list-machines -no-legend | wc -l)
count=$(fleetctl list-units -fields=unit -no-legend | grep -e "^$name" | wc -l)
if [ $count -gt $max ]; then
echo "Skipping $name, there are $count deployed units on $max fleet machines"
else
echo "Processing $name"
fleetctl list-units -fields=unit -no-legend | grep -e "^$name" | while read service; do
others=$(echo $service | cut -d. -f1-2)
tmpfile=/tmp/$service
fleetctl cat $service > $tmpfile
if ! grep X-Fleet $tmpfile > /dev/null; then
echo "" >> $tmpfile
echo "[X-Fleet]" >> $tmpfile
echo "Conflicts=$others*" >> $tmpfile
fleetctl destroy $tmpfile
fleetctl start $tmpfile
sleep 30
else
echo "Skipping $service, it already has an X-Fleet"
fi
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment