VMware Communities
0WayneH0
Hot Shot
Hot Shot

Any better way to automatically suspend VMs on host (Win7x64) shutdown than this way?

I've recently acquired a UPS for my main system. I found recently that random power outages and my RAID1 setup do not mix very well so the intent is to hook in the UPS to my host and upon a power failure the UPS software says it will "save my open files" (I have my doubts) and shut down my system. Unless by some miracle the UPS software and VMWare Workstation are on the same wavelength (perhaps there is some standard shutdown protocol there that both adhere to) then I fully expect my host to try to shut down, but be vetoed by VMWare due to having VMs in use.

Anyway to cut a long story short I found several possible ways to trigger a VM suspend, but most did not work. (e.g., group policy shut down script; doesn't execute, it seems, if an application (i.e., Workstation) vetos shutdown.

After some poking around I settled on triggering my shut down script (to suspend VMs) using Task Scheduler and using the System Event ID 1074 as the trigger (if I need some other trigger for UPS initiated shutdown I'll figure that out later).

The problem with what I have, even though it seems to work pretty well when testing shutdown from the host UI, is that I need to manually keep the script up to date (in terms of VMs on my system) and I have about 20 VMs at the current time, but that can and does change and I expect having to keep the script up to date will become an annoyance over time.

Here's what the script looks like for just one VM:

@echo off
@echo Dell XPS 420 Pre Shutdown Action...


REM Suspend Running VMs


"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" suspend "C:\...\My Virtual Machines\MyVM\MyVM.vmx"


REM Add any other VMs here.


REM Now VMs are suspended re-issue the shutdown (since Workstation would have vetoed the last attempt if any VMs were in use). Shouldn't need to force (/f) since we have now stopped VMs from running, plus we want to allow any pending disk commits required by VMware.
shutdown /s


REM Exit with success (if a VM is not running that will set errorlevel to non zero).
exit /b 0

I'm wondering if there is a way to issue a global suspend command or some other protocol for auto suspending VMs exists that I am not currently cognizant of?

If not I can live with what I have; it's in the name of data security after all, but it would be nice if you gurus out there know of a better way!

Thanks.

Reply
0 Kudos
4 Replies
pmunro
Contributor
Contributor

I run a script that hibernates the machine doing a shutdown -h, no need to suspend the VM individually; may need to issue a powercfg.exe -H on to turn on hibernation support before hand.

markdv77
Enthusiast
Enthusiast

0WayneH0 wrote:


The problem with what I have, even though it seems to work pretty well when testing shutdown from the host UI, is that I need to manually keep the script up to date (in terms of VMs on my system) and I have about 20 VMs at the current time, but that can and does change and I expect having to keep the script up to date will become an annoyance over time.

Hi,

It's possible to get a list of running vms using "vmrun list", which returns a list of paths to the .vmx files of running VMs.

Which is perfect for synthezising the appropriate shutdowns commands dynamically.

It would require some more advanced scripting than your current script... And I'm a linux user myself so I can't help you there.

Regards, Mark.

0WayneH0
Hot Shot
Hot Shot

Yes hibernation would make life simpler all round; I never considered that since I thought (incorrectly) that it may not play well with my system encryption, but I'm not sure where I got that idea from since it should be fine. I'm not sure if my UPS software will issue a hibernate command or just a balls out shutdown though. I'll have to see if it's only going to issue a shutdown command whether I can override that somehow. I also just read that the UPS I have will itself shut off 2 minutes after the shutdown command is executed, so if I have multiple VMs running 2 minutes might not be enough to suspend them all and shut down the way I have it configured now. Maybe hibernate is the best way to go if I can get it to work (i.e., get the UPS to initiate a hibernate either directly or indirectly); the only way I can see myself figuring this out is by simulating a power outage (unplugging the UPS).

Thanks for the info.

~~~~~~

Actually it looks like my UPS software will hibernate, so I just need to capture that and issue the command to my other machine running on the same UPS. That will save all the VM shutdown hoops I am currently jumping through.

Reply
0 Kudos
0WayneH0
Hot Shot
Hot Shot

Hey thanks for the tip; that I did not know and it will be handy if the hibernate thing doesn't go my way.

Thanks.

Reply
0 Kudos