From 858bbfae48e98128733f885a0b5665df03ab2452 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 1 Sep 2021 13:25:57 +0200 Subject: [qemu] Shutdown VM if VM viewer dies and VM remains running --- .../src/main/java/org/openslx/runvirt/plugin/qemu/App.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java index 78292e37..e1c2e311 100644 --- a/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java +++ b/core/modules/qemu/runvirt-plugin-qemu/src/main/java/org/openslx/runvirt/plugin/qemu/App.java @@ -219,13 +219,22 @@ public class App System.exit( 8 ); } + // stop VM if VM isn't turned off already (or if VM viewer) died + try { + vm.stop(); + } catch ( LibvirtVirtualMachineException e ) { + LOGGER.error( "Failed to shutdown orphaned VM: " + e.getLocalizedMessage() ); + hypervisor.close(); + System.exit( 9 ); + } + // undefine VM after usage try { hypervisor.deregisterVm( vm ); } catch ( LibvirtHypervisorException | LibvirtVirtualMachineException e ) { LOGGER.error( "Failed to undefine VM: " + e.getLocalizedMessage() ); hypervisor.close(); - System.exit( 9 ); + System.exit( 10 ); } // close connection to hypervisor -- cgit v1.2.3-55-g7522