I have searched for this, but cannot find anything--I am interested in automatically restarting a VM if someone accidentally shuts it down. I know this capability exists in Horizon, but I have been unable to find something similar in vCenter or the ESXi host config pages. Does anyone know if this is possible? I already have them set to start when the host starts.
There is no way that the application can understand accidental shutdown . So that is not possible . You might have to use a monitoring application like vROPS that can send you alerts when a VM is powered off/shutdown .
You can use vSphere HA (VM and Application Monitoring ) .
VM Monitoring restarts individual virtual machines if their VMware Tools heartbeats are not received within a set time. Similarly, Application Monitoring can restart a virtual machine if the heartbeats for an application it is running are not received. You can enable these features and configure the sensitivity with which vSphere HA monitors non-responsiveness.
That's good. I have several systems with single host clusters. They typically where our third site voting appliances live for things like storage arbitration. These have been configured for VM monitoring, so a failed VM will be rebooted.
Create cluster object, add the host to it.
Then you need to turn on HA under vSphere Availability. Obviously host recovery options are available to you, but the VM monitoring bits are, so under vSphere HA > VM Monitoring look for "Enable heartbeat monitoring" where you'll want to set it to "VM Monitoring Only".
Ah! Reading back on the original query, you are trying to find a way for ESXi to restart a VM that was 'accidently' shutdown. If the proper mechanisms for shutdown have been used, i.e. someone right clicked the VM in a web client and selected "power off" or "Shut down guest", then there would be no way for ESXi to distinguish between this being a deliberate or accidental act.
The solutions discussed so far will reset a VM that stops heartbeating, i.e. it has crashed or stalled internally, but not in the situation described originally. You were correct with your original assertion that this is something that Horizon does.
Another possibility would be to create a Scheduled Task on vCenter on the VM in question to "Power On" the VM hourly, so the worst that would happen would be for the VM to be offline for one hour. With some creative tasking (i.e. lots of Power On tasks) you could in theory have vCenter attempt to power on the VM at any frequency you wanted.
No. It won't. In fact I have found HA to be actually rather clever. When we wanted to test HA response to a host failure, we though all we'd need to do was to press and hold the power button on a server. The server would power off which would be seen by HA as a host failure and respond accordingly. It didn't happen... we have to pull the power cords. It's as if HA can detect that the power off was deliberate, and hence not a failure and didn't respond at all.
The scheduled task approach will work, but it is a bit clunky and will raise failures in the log when it attempts to power on the VM when the VM is already on.
I would ask why the "shutdown" option is even visible to users using RDP. Are they all administrators, because normally the start menu us reduced to only having the options to "Log off", "Disconnect" and "Lock". I think I would be looking to setup a local or group policy to remove the shutdown option from the menu. I.e. it's not really a VMware level problem at all.
Your point is well taken. This issue is arising because there have been a few times when someone has logged in and accidentally shut the machine down instead of logging out. There are only a couple of people with admin access and the ability to shutdown, but it is a license server, and so when it is down, no one can access the applications we use. I knew that Horizon offered the ability to force a VM to be on, and so hoped that I could do something similar in vCenter. I will look at scripting, but will just have to keep an eye on it for now.
Thanks for all the responses!
If accidental shutdowns is a common thing I would remove the shutdown and restart options through policy for everyone.
Admins can still shutdown if necessary by opening CMD window and using the command from there. This is highly unlikely to be done accidentally! LOL!