Opened 10 years ago
#14106 new enhancement
vboxdrv initscript $SHUTDOWN fix
Reported by: | old_man | Owned by: | |
---|---|---|---|
Component: | guest control | Version: | VirtualBox 4.3.26 |
Keywords: | vboxdrv, initscript, $SHUTDOWN | Cc: | |
Guest type: | all | Host type: | Linux |
Description
I experienced issues when shutting down VM's with the provided init scripts especially if they are not subject to the autostart service when setting the variable $SHUTDOWN_USERS as documented in /etc/init.d/vboxdrv: Either VboxXPCOMIPCD is not running any more and gives me error messages or the kernel modules cannot be unloaded properly because VboxXPCOMIPCD is still running when using
service vboxdrv stop
.
So I've done the following to /etc/init.d/vboxdrv:
- checking whether VboxXPIPCD ist still alive before trying to determine the status of running vms or trying to unload the kernel modules in stop_vms() and dmnstatus()
- enhancing the way the script waits for an ACPI shutdown with a configurable $SHUTDOWN_ACPI_TIMEOUT in stop_vms()
- provide a failover method $SHUTDOWN_ACPI_ACTION_FAILURE if ACPI shutdown is not successful (poweroff or savestate) in stop_vms()
254a255,278 > # the following is optional: > # SHUTDOWN_ACPI_TIMEOUT > # how long to wait for acpi shutdown of all vms > # SHUTDOWN_ACPI_ACTION_FAILURE=poweroff > # SHUTDOWN_ACPI_ACTION_FAILURE=savestate > # select failure action rather than terminating, > # defaults to poweroff > > poweroff_vms() { > begin_msg "Powering off remaining VMs" > for v in $1; do > $VBOXMANAGE --nologo controlvm $v poweroff > done > succ_msg > } > > savestate_vms() { > begin_msg "Powering off remaining VMs" > for v in $1; do > $VBOXMANAGE --nologo controlvm $v savestate > done > succ_msg > } > 258,282c282,323 < for i in $SHUTDOWN_USERS; do < # don't create the ipcd directory with wrong permissions! < if [ -d /tmp/.vbox-$i-ipc ]; then < export VBOX_IPC_SOCKETID="$i" < VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null` < if [ -n "$VMS" ]; then < if [ "$SHUTDOWN" = "poweroff" ]; then < begin_msg "Powering off remaining VMs" < for v in $VMS; do < $VBOXMANAGE --nologo controlvm $v poweroff < done < succ_msg < elif [ "$SHUTDOWN" = "acpibutton" ]; then < begin_msg "Sending ACPI power button event to remaining VMs" < for v in $VMS; do < $VBOXMANAGE --nologo controlvm $v acpipowerbutton < wait=30 < done < succ_msg < elif [ "$SHUTDOWN" = "savestate" ]; then < begin_msg "Saving state of remaining VMs" < for v in $VMS; do < $VBOXMANAGE --nologo controlvm $v savestate < done < succ_msg --- > #see whether we can contact ipcd to avoid error message > if pgrep VBoxXPCOMIPCD>/dev/null; then > for i in $SHUTDOWN_USERS; do > # don't create the ipcd directory with wrong permissions! > if [ -d /tmp/.vbox-$i-ipc ]; then > export VBOX_IPC_SOCKETID="$i" > VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null` > if [ -n "$VMS" ]; then > if [ "$SHUTDOWN" = "poweroff" ]; then > poweroff_vms $VMS > elif [ "$SHUTDOWN" = "acpibutton" ]; then > begin_msg "Sending ACPI power button event to remaining VMs" > for v in $VMS; do > $VBOXMANAGE --nologo controlvm $v acpipowerbutton > done > succ_msg > if [ -n "$SHUTDOWN_ACPI_TIMEOUT" ];then > wait=$SHUTDOWN_ACPI_TIMEOUT > else > wait=30 > fi > begin_msg "Waiting for $wait seconds for VM shutdown" > c=0 > while [ -n "`$VBOXMANAGE --nologo list runningvms`" ] && [ $c -le $wait ]; do > echo -n '.' > sleep 1 > c=$(($c+1)) > done > VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null` > if [ -n "$VMS" ];then > fail_msg > if [ -z "$SHUTDOWN_ACPI_ACTION_FAILURE" ] || [ "$SHUTDOWN_ACPI_ACTION_FAILURE" = "poweroff" ] ;then > poweroff_vms $VMS > elif [ "$SHUTDOWN_ACPI_ACTION_FAILURE" = "savestate" ]; then > savestate $VMS > fi > else > succ_msg > fi > elif [ "$SHUTDOWN" = "savestate" ]; then > savestate_vms $VMS > fi 284a326,338 > done > begin_msg 'waiting for XPCOMIPCD to stop ' > timeout=20 > c=0 > while pgrep VBoxXPCOMIPCD>/dev/null && [ $c -le $timeout ] ; do > echo -n '.' > sleep 1 > c=$(($c+1)) > done > if pgrep VBoxXPCOMIPCD>/dev/null;then > fail_msg > else > succ_msg 286,291d339 < done < # wait for some seconds when doing ACPI shutdown < if [ "$wait" -ne 0 ]; then < begin_msg "Waiting for $wait seconds for VM shutdown" < sleep $wait < succ_msg 378,387c426,437 < for i in $SHUTDOWN_USERS; do < # don't create the ipcd directory with wrong permissions! < if [ -d /tmp/.vbox-$i-ipc ]; then < export VBOX_IPC_SOCKETID="$i" < VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null` < if [ -n "$VMS" ]; then < echo "The following VMs are currently running:" < for v in $VMS; do < echo " $v" < done --- > if pgrep VBoxXPCOMIPCD>/dev/null; then > for i in $SHUTDOWN_USERS; do > # don't create the ipcd directory with wrong permissions! > if [ -d /tmp/.vbox-$i-ipc ]; then > export VBOX_IPC_SOCKETID="$i" > VMS=`$VBOXMANAGE --nologo list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/' 2>/dev/null` > if [ -n "$VMS" ]; then > echo "The following VMs are currently running:" > for v in $VMS; do > echo " $v" > done > fi 389,390c439,440 < fi < done --- > done > fi
See also https://forums.virtualbox.org/viewtopic.php?f=9&t=67546 for a better formatted diff.