public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container v2] fix #3927: no error code when stopping a stopped container
@ 2022-06-24 14:02 Daniel Tschlatscher
  0 siblings, 0 replies; only message in thread
From: Daniel Tschlatscher @ 2022-06-24 14:02 UTC (permalink / raw)
  To: pve-devel

Stopping a container that was already stopped now no longer returns an
error code. This behaviour was adapted to match the return values for
VMs, to get a more consistent API. Both VMs and containers now return
an error when starting an already started guest, and both do not show
an error when stopping an already stopped guest.

Even though this is a really small change, some users might rely on
the containers returning the error. Therefore, this should probably
be considered a breaking change.

This change also has another side effect:
When the stop command for an HA-managed container was invoked, but the
container would stop in the meantime (e.g. because it crashed, ...), a
condition would arise which meant that the API call would die and
never reach the HA manager. Therefore not updating the requested HA
state for the container.
As a result, the container would be started again once the next HA
check was scheduled, in spite of the expected HA state being 'stopped'

This patches fixes this issue and brings it more in line with the
expected behaviour.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
---
Changes from v2:
* This patch no longer includes also changing the return codes for
  already started containers.

 src/PVE/API2/LXC/Status.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
index f7e3128..2c8fb4a 100644
--- a/src/PVE/API2/LXC/Status.pm
+++ b/src/PVE/API2/LXC/Status.pm
@@ -238,8 +238,6 @@ __PACKAGE__->register_method({
 	raise_param_exc({ skiplock => "Only root may use this option." })
 	    if $skiplock && $authuser ne 'root@pam';
 
-	die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid);
-
 	if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
 
 	    my $hacmd = sub {
@@ -260,6 +258,8 @@ __PACKAGE__->register_method({
 
 		syslog('info', "stopping CT $vmid: $upid\n");
 
+		return if !PVE::LXC::check_running($vmid);
+
 		my $conf = PVE::LXC::Config->load_config($vmid);
 		if (!$skiplock && !PVE::LXC::Config->has_lock($conf, 'mounted')) {
 		    PVE::LXC::Config->check_lock($conf);
-- 
2.30.2





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-24 14:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 14:02 [pve-devel] [PATCH container v2] fix #3927: no error code when stopping a stopped container Daniel Tschlatscher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal