]> git.proxmox.com Git - pve-container.git/commitdiff
fix #2200: vm_stop: add nokill-after-timeout parameter
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 8 May 2019 07:07:22 +0000 (07:07 +0000)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 10 May 2019 09:47:45 +0000 (09:47 +0000)
This allows to have the same semantics as qemu-server:
* immediate hard-kill
* shutdown with kill after timeout
* shutdown without kill after timeout

And thus we finally can move the vm_shutdown API call to a correct
semantic, i.e., do not immediate hard kill if forceStop is not passed
but rather see it as stop after timeout knob.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/API2/LXC/Status.pm
src/PVE/LXC.pm

index 95775fee7b4daab2dbcf63bdbdc8d2d910042115..8eeb864cd303858a67b1f26ba6621f696d4c43a4 100644 (file)
@@ -369,7 +369,7 @@ __PACKAGE__->register_method({
 
                PVE::LXC::Config->check_lock($conf);
 
-               PVE::LXC::vm_stop($vmid, $param->{forceStop}, $timeout);
+               PVE::LXC::vm_stop($vmid, 0, $timeout, $param->{forceStop});
 
                return;
            };
index f8fc37e33cbb0e8af1643e86dbad38e7bb096c0d..62b6b8ca62e233577cede2bbf52ec4adf03eb24b 100644 (file)
@@ -1938,8 +1938,11 @@ sub vm_start {
 # This is necessary because we want the post-stop hook to have completed its
 # unmount-all step, but post-stop happens after lxc puts the container into the
 # STOPPED state.
+# $kill - if true it will always do an immediate hard-stop
+# $shutdown_timeout - the timeout to wait for a gracefull shutdown
+# $kill_after_timeout - if true, send a hardstop if shutdown timed out
 sub vm_stop {
-    my ($vmid, $kill, $shutdown_timeout) = @_;
+    my ($vmid, $kill, $shutdown_timeout, $kill_after_timeout) = @_;
 
     # Open the container's command socket.
     my $path = "\0/var/lib/lxc/$vmid/command";
@@ -1961,10 +1964,15 @@ sub vm_stop {
 
     if ($kill) {
        push @$cmd, '--kill'; # doesn't allow timeouts
-    } elsif (defined($shutdown_timeout)) {
-       push @$cmd, '--timeout', $shutdown_timeout;
-       # Give run_command 5 extra seconds
-       $shutdown_timeout += 5;
+    } else {
+       # lxc-stop uses a default timeout
+       push @$cmd, '--nokill' if !$kill_after_timeout;
+
+       if (defined($shutdown_timeout)) {
+           push @$cmd, '--timeout', $shutdown_timeout;
+           # Give run_command 5 extra seconds
+           $shutdown_timeout += 5;
+       }
     }
 
     eval { PVE::Tools::run_command($cmd, timeout => $shutdown_timeout) };