public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container v2] fix #3927: no error code when stopping a stopped container
Date: Fri, 24 Jun 2022 16:02:09 +0200	[thread overview]
Message-ID: <20220624140209.411405-1-d.tschlatscher@proxmox.com> (raw)

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





                 reply	other threads:[~2022-06-24 14:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220624140209.411405-1-d.tschlatscher@proxmox.com \
    --to=d.tschlatscher@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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