]> git.proxmox.com Git - qemu-server.git/commitdiff
qm: cleanup: detect and handle reboot trigger
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 11 Sep 2019 12:07:43 +0000 (14:07 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 11 Sep 2019 12:13:35 +0000 (14:13 +0200)
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@proxmox.com>
PVE/CLI/qm.pm
PVE/QemuServer.pm

index 3aae23c6d2a87539aeaba5b2f60ec69e1af59d62..74905b2db669a380694f08b29e0db5ad384e4fb2 100755 (executable)
@@ -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,21 @@ __PACKAGE__->register_method({
                PVE::QemuServer::vm_stop_cleanup($storecfg, $vmid, $conf, 0, 0);
            }
            PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop');
+
+           $restart = eval { PVE::QemuServer::clear_reboot_request($vmid) };
+           warn $@ if $@;
        });
 
        warn "Finished cleanup for $vmid\n";
 
+       if ($restart) {
+           warn "Restarting VM $vmid\n";
+           PVE::API2::Qemu->vm_start({
+               vmid => $vmid,
+               node => $nodename,
+           });
+       }
+
        return undef;
     }});
 
index 367d0805b1d761fb72bb8456735229688e5e4c06..b420ffbdb3a4def3a9a8d4cce0df3705dc4c1f04 100644 (file)
@@ -5340,6 +5340,10 @@ sub vm_start {
 
        die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
 
+       # clean up leftover reboot request files
+       eval { clear_reboot_request($vmid); };
+       warn $@ if $@;
+
        if (!$statefile && scalar(keys %{$conf->{pending}})) {
            vmconfig_apply_pending($vmid, $conf, $storecfg);
            $conf = PVE::QemuConfig->load_config($vmid); # update/reload