HA and poweroff inside VM

gurubert

Distinguished Member
Mar 12, 2015
1,124
301
153
Berlin, Germany
www.heinlein-consulting.de
When a VM is protected by HA and a poweroff runs inside the VM the VM is happily started again by the HA manager.

Is it possible to tell the HA manager from within the VM (via qemu-guest-agent maybe) that the VM should stay powered off?
 
Last edited:
Would it be technically possible to implement this as a feature?
I have played around with it. By adding something like

Diff:
--- /usr/share/perl5/PVE/CLI/qm.pm.orig    2024-10-08 10:40:59.461914057 +0200
+++ /usr/share/perl5/PVE/CLI/qm.pm    2024-10-08 13:16:26.657357364 +0200
@@ -937,6 +937,14 @@
         }
         PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop');
 
+        if ($guest) {
+        warn "guest stopped from inside, sending 'stop' to HA\n";
+        PVE::API2::Qemu->vm_stop({
+            vmid => $vmid,
+            %node,
+        });
+        }
+
         $restart = eval { PVE::QemuServer::clear_reboot_request($vmid) };
         warn $@ if $@;
     });

to the cleanup method in qm we could send an extra vm_stop to switch HA-state to stopped if guest is stopped from inside. The Problem here is that in fact guests are being stopped from inside event they are stopped from the GUI because an ACPI (or guest-agent) is triggered stopping the VM from the inside. In the case of non-HA managed guests this leads to the error that the extra vm_stop can't lock the guests lockfile.

I think it is possible to implement this as a feature and make this `shutdown from guest even with HA` optional. To do this, however, much more knowledge of the code is needed.
 
  • Like
Reactions: Zerstoiber