[pve-devel] [PATCH qemu-server v2 2/5] qm: cleanup: detect and handle reboot trigger
Dominik Csapak
d.csapak at proxmox.com
Fri Aug 23 10:55:57 CEST 2019
if the reboot trigger file was set, start the vm again
also cleanup the reboot trigger on vm startup, to prevent
leftover files to trigger a reboot at the next shutdown
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
change from rfc:
* use remove_reboot_trigger sub
* cleanup also on vm start
PVE/CLI/qm.pm | 13 +++++++++++++
PVE/QemuServer.pm | 2 ++
2 files changed, 15 insertions(+)
diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 3aae23c..f9b0fd7 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 (PVE::QemuServer::remove_reboot_trigger($vmid)) {
+ $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;
}});
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index d1767a9..cc0c95e 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5307,6 +5307,8 @@ sub vm_start {
PVE::QemuConfig->check_lock($conf)
if !($skiplock || $is_suspended);
+ PVE::QemuServer::remove_reboot_trigger($vmid);
+
die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
if (!$statefile && scalar(keys %{$conf->{pending}})) {
--
2.20.1
More information about the pve-devel
mailing list