All my servers are running on VMware Worstation virtual machines. Virtual machines have the advantages of easy management and ability of restoring to earlier snapshots, which are quite valuable during development.
Some of my virtual machines need to be running all the time when the physical computer is on. VMware Workstation provides an AutoStart feature to allow shared virtual machines to automatically start during the host system boot-up. However, the built-in AutoStart feature turns out to have limitations which make it useless for my situation.
What's Wrong with AutoStart?
There are 2 major problems with VMware Workstation's implementation of AutoStart feature that made me to seek for an alternative solution:
- Only shared virtual machines can be auto started. This in itself is not a problem. You just have to set your virtual machines to be shared. and then configure AutoStart. But, there are restrictions placed on shared virtual machines. One of them is that you can't use physical disks with shared VMs. Since one of my VMs uses physical disks, it can't be made shared, let alone AutoStart.
- Another problem was discovered when I noticed MySQL server on an AutoStart VM had to recover from corruption every time the host computer was restarted. I thought the AutoStart feature would also auto-shutdown/suspend VMs when the host is shutting down or rebooting, and apparently I thought wrong. The feature only does its name implies, which is auto starting VMs. That is simply unacceptable to allow possible data loss.
An Alternative Way to Auto Start/Stop VMs
Here I will present the script and procedure I devised to allow VMs with physical disks to automatically start when the host boots up and suspend/shutdown when the host shuts down. All these are done using existing software already installed with VMware Workstation and on a Windows 7 Home Premium system.
The script I wrote is in PowerShell. There is no special reason for using PowerShell. I only used it just for fun, and are not very good with it. You are welcome to modify it and make it better. To control VMs, I use the 'vmrun.exe' program came with VMware Workstation.
Once I had the script working as desired, I needed a way to run it during the host system starting up and shutting down. There are maybe 3 different ways to achieve that on a Windows 7 system. However, I found using the Task Scheduler may be the simplest and universal approach.
Then, I set up my VMs to allow my auto start/stop script to process, and tested it on the host system. At the end I have a satisfactory way to let my VMs start and suspend automatically.