Q: How can I start my virtual machines in a specific order? For example, how do I start them when the preceding VM has completed startup and Hyper-V detects its heartbeat?

This utility not only shuts down virtual machines, it can also start VMs up, in order.

John Savill

October 28, 2011

4 Min Read
ITPro Today logo in a gray background | ITPro Today

A: A few months ago I wrote a utility to shut down virtual machines (VMs) in order. It wouldn’t shut down the next VM or group of VMs until the previous VM or VM group had completed shutdown.

Now I've created a new utility that not only does a shutdown but performs a startup. It allows groups of VMs to be started, and only when all VMs in the group have a heartbeat or have met their maximum allowed start time will the next group of VMs be started. This is very useful when you have dependencies between VMs.

You create a configuration file which has the format:

|||| For example, the configuration line below is for VM savdaldc10,savdaldc10|savdalbfs01.savilltech.net|180|300|1|20where VM savdaldc10 on Hyper-V host savdalbfs01.savilltech.net has 180 seconds to stop and 300 seconds to start. 

The 1 means if the VM hasn’t shut down within 180 seconds, it will be turned off. 

The 20 stands for an extra 20 seconds that will be waited after the VM’s heartbeat is detected during startup before moving to the next VM. 

This delay of extra seconds is useful for turning on a SQL Server, for example. Even though the VM heartbeat is there, it doesn’t mean SQL Server would have started, so I give it some extra time. 

A value of 0 means no extra wait.If you want it to wait the full start time, ignoring when the heartbeat is detected, use a W, as insavdaldc10|savdalbfs01.savilltech.net|180|300|1|WYou can see I changed the 20 to W, which means it will always wait the full start time.

The screen shot below shows my configuration file for my environment. In my example all the VMs are on the same Hyper-V host. However, the utility can be run remotely, and you can have a mix of VMs on many different Hyper-V hosts. 



Note the line breaks, which is where I have defined many different groups. Also note the VM that should start first and stop last should be at the top of the file, working down in start/reverse stop order:

To actually use the utility, you call mngvms.exe and pass the text file containing the VMs. You then tell it to use group logic (1) or just start/stop the VMs one at a time, ignoring groups (0). 

The next number is a logging level: 2 is basic info to screen (1 is silent). You then specify if the VMs should be stopped (stop), started (start), or restarted (restart). 

Below is an example of a restart. You can see they are shut down in group order, then started in group order. 

Several symbols indicate status: During the start, a period (.) means VMs starting with none having heartbeat yet; a dash (-) means some VMs have a heartbeat in the group but not all; and a right arrow (>) means all VMs in the group have a heartbeat, and we are now waiting either the extra start time or the VM was configured to always wait the full start time:

D:projectsVBScripts>mngvms.exe vmlist.txt 1 2 restartStopVMs by John Savill ([email protected])Please see http://www.savilltech.com for help on this utility
Copyright 2011 John Savill

Stopping using groups
Stopping group 10
Stopping Savdalclient4.savilltech.net currently in state running.
Stopping Savdalclient3.savilltech.net currently in state running.
Stopping Savdalclient2.savilltech.net currently in state running................................

Stopping group 9
Stopping Savdalclient.savilltech.net currently in state running....................

Stopping group 8
Stopping savdalsmdw01 currently in state running.
Stopping Savdalsm01 currently in state running................

Stopping group 7
Stopping Savdalync01 currently in state running.
Stopping Savdalcb01 currently in state running....................

Stopping group 6
Stopping Savdalappv01 currently in state running.
Stopping Savdalcm01 currently in state running.......................

Stopping group 5
Stopping savdalscvmm currently in state running.
Stopping savdalex10 currently in state running....................

Stopping group 4
Stopping savdaldpm01 currently in state running..................

Stopping group 3
Stopping savdalom01 currently in state running....................

Stopping group 2
Stopping savdalts01 currently in state running.
Stopping savdalfs01 currently in state running....................

Stopping group 1
Stopping savdalrodc01 currently in state running.
Stopping savdaldc11 currently in state running........................

Stopping group 0
Stopping savdaldc10 currently in state running..............

Starting using groups
Starting group 0
Starting savdaldc10 currently in state powered off.......................................................>>>>>>>>>>>>>>>>>>>>

Starting group 1
Starting savdaldc11 currently in state powered off.
Starting savdalrodc01 currently in state powered off.............................................................---------------

Starting group 2
Starting savdalfs01 currently in state powered off.
Starting savdalts01 currently in state powered off.................................................................................................--

Starting group 3
Starting savdalom01 currently in state powered off................................>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Starting group 4
Starting savdaldpm01 currently in state powered off.........................................................>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 

Starting group 5
Starting savdalex10 currently in state powered off.
Starting savdalscvmm currently in state powered off..........................................................................................--------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Starting group 6
Starting Savdalcm01 currently in state powered off. 
Starting Savdalappv01 currently in state powered off.................................................................................................................................----

Starting group 7
Starting Savdalcb01 currently in state powered off.
Starting Savdalync01 currently in state powered off.......................................................................................-----

Starting group 8
Starting Savdalsm01 currently in state powered off.Starting savdalsmdw01 currently in state powered off................................................................................................................................................-----------

Starting group 9
Starting Savdalclient.savilltech.net currently in state powered off...................................................................>>>>>>>>>>

Starting group 10
Starting Savdalclient2.savilltech.net currently in state powered off.
Starting Savdalclient3.savilltech.net currently in state powered off.
Starting Savdalclient4.savilltech.net currently in state powered off.............................................................................-----------------

Note in my example that if I just change the command to mngvms.exe vmlist.txt 0 2 restart
the VMs wouldn’t use group logic and would just stop and start in order.

For more information check out my website. You can download it at my website too.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like