Last active
February 25, 2017 19:14
-
-
Save technovangelist/a3b9347d0251b35d43d0 to your computer and use it in GitHub Desktop.
cron script to shutdown boot2docker
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/zsh | |
# set cron to run this every couple of minutes and it will shutdown boot2docker | |
# when its been running with no processes for maxminutes | |
maxminutes=10 | |
local bdout | |
local dpqout | |
bdout=$(boot2docker status) 2>/dev/null | |
if [[ $bdout = "running" ]]; then | |
echo "boot2docker running" | |
dpqout=$(docker ps -q) 2>/dev/null | |
if [[ $dpqout = "" ]]; then | |
echo "but no processes running" | |
if [[ -f ~/.bddowntime ]]; then | |
echo "downtime file exists" | |
while read firsttime; do | |
local nowtime | |
nowtime=$(date +"%s") | |
diff=$(($nowtime-$firsttime)) | |
(( maxseconds=$maxminutes*60 )) | |
echo $diff | |
echo $maxseconds | |
if [[ $diff -gt $maxseconds ]]; then | |
echo "Been down a while. Shutting down boot2docker" | |
echo $diff | |
boot2docker down | |
fi | |
done < ~/.bddowntime | |
else | |
echo "it doesnt exist so creating downtime file" | |
echo $(date +"%s") > ~/.bddowntime | |
fi | |
else | |
echo "and docker ps has processes" | |
fi | |
else | |
echo "not running" | |
if [[ -f ~/.bddowntime ]]; then | |
echo "and the file was there" | |
rm ~/.bddowntime | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment