]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
Add timeout parameter for shutdown
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 10 Oct 2019 10:25:06 +0000 (12:25 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 11 Oct 2019 10:25:53 +0000 (12:25 +0200)
Introduces a timeout parameter for shutting a resource down.
If the parameter is 0, we perform a hard stop instead of a shutdown.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
src/PVE/HA/LRM.pm
src/PVE/HA/Resources.pm
src/PVE/HA/Resources/PVECT.pm
src/PVE/HA/Resources/PVEVM.pm

index 5b986a454cc064b56d380e82bb97cc9015a0a509..b5ef8b87252912bcc425d48732879932ad93051f 100644 (file)
@@ -532,7 +532,7 @@ sub manage_resources {
        my $req_state = $sd->{state};
        next if !defined($req_state);
        next if $req_state eq 'freeze';
-       $self->queue_resource_command($sid, $sd->{uid}, $req_state, {'target' => $sd->{target}});
+       $self->queue_resource_command($sid, $sd->{uid}, $req_state, {'target' => $sd->{target}, 'timeout' => $sd->{timeout}});
     }
 
     return $self->run_workers();
@@ -771,9 +771,13 @@ sub exec_resource_agent {
 
        return SUCCESS if !$running;
 
-       $haenv->log("info", "stopping service $sid");
+       if (defined($params->{timeout})) {
+           $haenv->log("info", "stopping service $sid (timeout=$params->{timeout})");
+       } else {
+           $haenv->log("info", "stopping service $sid");
+       }
 
-       $plugin->shutdown($haenv, $id);
+       $plugin->shutdown($haenv, $id, $params->{timeout});
 
        $running = $plugin->check_running($haenv, $id);
 
index 7c373bcab0ce281cfab1ff5ee455ffa3a917c798..835c3148180efa461b2ef8d97542919e8a7cfaa5 100644 (file)
@@ -126,7 +126,7 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     die "implement in subclass";
 }
index a0f05f44125f5bd29ce41e8669da803297e16eba..282f4ef3a06451a84e63ae26ddd61b84adc265e5 100644 (file)
@@ -74,18 +74,24 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     my $nodename = $haenv->nodename();
-    my $shutdown_timeout = 60; # fixme: make this configurable
+    my $shutdown_timeout = $timeout // 60;
 
+    my $upid;
     my $params = {
        node => $nodename,
        vmid => $id,
-       timeout => $shutdown_timeout,
     };
 
-    my $upid = PVE::API2::LXC::Status->vm_shutdown($params);
+    if ($shutdown_timeout) {
+       $params->{timeout} = $shutdown_timeout;
+       $upid = PVE::API2::LXC::Status->vm_shutdown($params);
+    } else {
+       $upid = PVE::API2::LXC::Status->vm_stop($params);
+    }
+
     PVE::HA::Tools::upid_wait($upid, $haenv);
 }
 
index 0a37cf6e6efca3115ce6d375c66118ee9cca5938..aad073d66f1d3857c020a99ae7989cdf04670fde 100644 (file)
@@ -72,19 +72,25 @@ sub start {
 }
 
 sub shutdown {
-    my ($class, $haenv, $id) = @_;
+    my ($class, $haenv, $id, $timeout) = @_;
 
     my $nodename = $haenv->nodename();
-    my $shutdown_timeout = 60; # fixme: make this configurable
+    my $shutdown_timeout = $timeout // 60;
 
+    my $upid;
     my $params = {
        node => $nodename,
        vmid => $id,
-       timeout => $shutdown_timeout,
-       forceStop => 1,
     };
 
-    my $upid = PVE::API2::Qemu->vm_shutdown($params);
+    if ($shutdown_timeout) {
+       $params->{timeout} = $shutdown_timeout;
+       $params->{forceStop} = 1;
+       $upid = PVE::API2::Qemu->vm_shutdown($params);
+    } else {
+       $upid = PVE::API2::Qemu->vm_stop($params);
+    }
+
     PVE::HA::Tools::upid_wait($upid, $haenv);
 }