Created
May 13, 2015 09:06
-
-
Save egbertp/5542def7dbc98f0415ab to your computer and use it in GitHub Desktop.
Rebalance docker within fleet
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
#!/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