| 1 | #!/bin/bash
|
|---|
| 2 | ################################################################################
|
|---|
| 3 | # Author: Travis McDermott #
|
|---|
| 4 | # Date of Creation: 8/28/2012 #
|
|---|
| 5 | # Last Revision: 8/28/2012 #
|
|---|
| 6 | # Synopsis: Safely saves machine state of virtualbox VMs. Depends on vboxtool. #
|
|---|
| 7 | # Originally concieved to address a bug which caused system halt to loop #
|
|---|
| 8 | # loop endlessly while waiting for host interface to be freed, even after #
|
|---|
| 9 | # machines were successfully stopped. #
|
|---|
| 10 | ################################################################################
|
|---|
| 11 | vmuser="vboxuser"
|
|---|
| 12 | vboxtool="/usr/local/bin/vboxtool"
|
|---|
| 13 |
|
|---|
| 14 | halt_wait() {
|
|---|
| 15 | runningVMs=$($vboxtool showrun | wc -l )
|
|---|
| 16 | if [ $runningVMs != 0 ]; then
|
|---|
| 17 | sleep 5
|
|---|
| 18 | echo "saving state of $runningVMs VMs..."
|
|---|
| 19 | halt_wait
|
|---|
| 20 | else
|
|---|
| 21 | return 0
|
|---|
| 22 | fi
|
|---|
| 23 | }
|
|---|
| 24 | su - $vmuser -c "$vboxtool save"
|
|---|
| 25 | halt_wait
|
|---|
| 26 | modprobe -l vboxnetadp
|
|---|
| 27 | modprobe -l vboxnetflt
|
|---|
| 28 | modprobe -l vboxdrv
|
|---|