[pve-devel] [RFC PATCH 1/4] qm: cleanup: detect and handle reboot trigger

Dominik Csapak d.csapak at proxmox.com
Wed Aug 14 16:20:27 CEST 2019


if the reboot trigger file was set, start the vm again

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/CLI/qm.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 3aae23c..031aa49 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -763,6 +763,7 @@ __PACKAGE__->register_method({
 	my $vmid = $param->{vmid};
 	my $clean = $param->{'clean-shutdown'};
 	my $guest = $param->{'guest-requested'};
+	my $restart = 0;
 
 	# return if we do not have the config anymore
 	return if !-f PVE::QemuConfig->config_file($vmid);
@@ -790,10 +791,22 @@ __PACKAGE__->register_method({
 		PVE::QemuServer::vm_stop_cleanup($storecfg, $vmid, $conf, 0, 0);
 	    }
 	    PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop');
+
+	    if (unlink("/var/lib/qemu-server/$vmid.reboot")) {
+		$restart = 1;
+	    }
 	});
 
 	warn "Finished cleanup for $vmid\n";
 
+	if ($restart) {
+	    warn "Restarting VM $vmid\n";
+	    PVE::API2::Qemu->vm_start({
+		vmid => $vmid,
+		node => $nodename,
+	    });
+	}
+
 	return undef;
     }});
 
-- 
2.20.1




More information about the pve-devel mailing list