Created
April 27, 2015 14:05
-
-
Save un1t/99c5a2ac998c173ae16d to your computer and use it in GitHub Desktop.
Suspend Vagrant boxes before shutdown on Ubuntu
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 | |
# save it to "/etc/init.d/vagrant-boxes" | |
# sudo update-rc.d vagrant-boxes defaults 99 01 | |
RETVAL=0 | |
USER='ilya' | |
stop() { | |
LIST=`sudo -u $USER vagrant global-status | grep running | awk '{print $1}'` | |
for i in `echo $LIST`; do | |
echo [Vagrant] suspend $i.. | |
sudo -u $USER vagrant suspend $i | |
done | |
} | |
status() { | |
sudo -u $USER vagrant global-status | grep running | awk '{print $1,$4}' | |
} | |
case "$1" in | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
*) (10) | |
echo $"Usage: $0 {stop|status}" | |
RETVAL=1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment