I have a Windows Server 2012R2 hyper-v host. It is running a number of VMs, including a few linux VMs.
I have one linux VM that has been occationally, but somewhat regularly crashing somewhere in the kernel, resulting in the VM becoming completely unresponsive.
I know hyper-v has a "heartbeat" facility, and it successfully detects the VM crashing as a loss-of-heartbeat.
However, I'm at a loss as to how to set up hyper-v so that it actually does anything with the heartbeat signal. Apparently at one point, there was the option to reset the VM if a heartbeat is lost for > 1 minute, but it's either been removed, or placed somewhere I cannot find.
I only have this one server, so doing things like clustering or fail-over are not really viable (this is a home lab server).
Before anyone comments, Yes, I am trying to track down the cause of the crash in the VM, but it's irregularity has been making it difficult.
powershell is your rescue:
just add this to task scheduler.
If You VM does not support heartbeat then modify this to ping the VM instead of checking the HB.
I needed a solution for monitoring the heartbeat of all Hyper-V virtual machines and automatically preforming a hard reset when the VM locked up. As you may already know. it seems as though you can do this using Hyper-V when you have a cluster setup, but with only a single Hyper-V host, that is not possible without some custom scripting.
I found a nice VBS the monitors the heartbeat of all systems, and even has a configurable retry count and grace period in the latest version. The original script and description can be found here. It'd be a good idea to schedule this to run with system startup (don't just place it in the startup folder, because that would require the Hyper-V Administrator to login to the system before the script would start running).
For the sake of preserving the script, I've also pasted the latest version of the .VBS code (with retry count and grace period) below.
UPDATE: The latest version of the script actually had some bugs, so the script below has been modified and I confirmed it is working on Server 2012R2.
\v2
needed to be added to line #20 and10
needed to be changed to11
on line #4 of theVMHardReset
function.