Page 1 of 1
Best practice ACPI shutdown guest on host shutdown
Posted: 23. Mar 2015, 23:05
by SixOThree
I am having some difficulty finding best practice solution for sending ACPI shutdown to the guest on host shutdown. We have a machine that installs Windows Updates on a regular basis and it appears the guest machines are shut down abruptly when this computer reboots.
What is the solution that I should be using for this problem?
Thank you.
Re: Best practice ACPI shutdown guest on host shutdown
Posted: 24. Mar 2015, 00:16
by noteirak
There won't be any magical solution: even if you can get the ACPI Power Button event, the guest OS still takes time to power off. No guarantee it will be done on time.
Now about the best practice: there isn't on a Windows host AFAIK. The best practice is about not letting Windows automatically install & reboot your system.
Re: Best practice ACPI shutdown guest on host shutdown
Posted: 24. Mar 2015, 01:31
by SixOThree
Is there any solution?
These are relatively lightweight Ubuntu servers that seem to respond fairly quickly to a shutdown command. Unfortunately even with manual updates there is no way I can guarantee these machines are only shut down by a human (who knows and remembers the correct procedure). Additionally this area is prone to power failures and this particular host will shut down when battery falls below a certain percent.
Re: Best practice ACPI shutdown guest on host shutdown
Posted: 24. Mar 2015, 01:34
by noteirak
I am not sure about the reboot/power off of the host TBH. I'll let other answer.
About low battery, there is a built-in feature :
https://www.virtualbox.org/manual/ch09. ... owertweaks
Re: Best practice ACPI shutdown guest on host shutdown
Posted: 24. Mar 2015, 13:11
by scottgus1
You can change the host automatic Windows Updates to a script-launched Windows Updates, which script could also shut down your guests using Vboxmanage before running the Windows Updates. See:
viewtopic.php?f=6&t=64741 for the Windows batch file command line and VBS script that runs Windows Updates, and
viewtopic.php?f=1&t=61861 for Vboxmanage commands to run on running guests without knowing ahead of time which guests are running.
Also, I have found in my experiments that guests may remain running and restore properly if the Windows host is hibernated for power-loss events. After all, the guests are really just programs running on the host. A more sure way to get guests safely put away in a power outage situation is to run a batch file using two Vboxmanage commands in succession on each guest: one to order an ACPI shutdown and the next to immediately order a save-state. The guest will get save-stated in the shutdown process, so when it's restored later it will continue shutting down and be ready for a fresh reboot. Gets the guest out of the way quickly but makes sure it will be ready for proper running when the host gets powered up again. Have a battery backup that can keep the host alive for some two to three times as long as necessary to get all the guests reboot-save-stated. If possible the battery backup software should have a "Run this program when the computer is on battery" function. You write your guest-save-state batch file and point the battery backup software at it. If the battery backup software doesn't have such a function or won't reliably call your batch file, Windows can run a VBS script to monitor the state of the battery backup and run things when on battery for more than a certain amount of time:
Code: Select all
Set Shell = WScript.CreateObject("WScript.Shell")
function testbat()
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Battery",,48)
For Each objItem in colItems
batstat = objItem.BatteryStatus
Next
Set colItems = nothing
testbat = batstat
end Function
dummy=shell.popup("UPS VM monitor started",3,"UPSvmsavsstateMonitor.vbs")
do 'main
do
if testbat = 1 then exit do 'status 2: on AC power; 1: on battery; 6: service
wscript.sleep 10000 'check every 10 seconds
loop
wscript.sleep 10000 'delay 10 seconds, then re-test
if testbat = 1 then 'still on battery
'here's where the decided action takes place to shut down the guests & host
if true then 'true will run a batch file. change to false to just hibernate the host
'this line runs another batch file with Vboxmanage commands to handle the guests as desired, then shut down the host
shell.run "C:\vmbackupscript\Win7UPShibernate.cmd nopause"
else
'this line will just hibernate the host without doing anything to the guests
shell.run "rundll32 powrprof.dll,SetSuspendState"
end if
dummy=shell.popup("UPS status 1, on battery",3,"UPSvmsavsstateMonitor.vbs")
wscript.quit
end if
loop 'main
If you do choose to have the battery backup software run a script, or use a VBS script to monitor the battery status, be sure to not have other timers on the battery backup software that could shut down the host before the script is finished running, and also be sure to issue the shutdown or hibernate command at the end of your script.
Re: Best practice ACPI shutdown guest on host shutdown
Posted: 25. Mar 2015, 21:02
by SixOThree
Thank you everyone. This is all extremely helpful.