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>
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();
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);
}
sub shutdown {
- my ($class, $haenv, $id) = @_;
+ my ($class, $haenv, $id, $timeout) = @_;
die "implement in subclass";
}
}
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);
}
}
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);
}