[pve-devel] [PATCH v3 container] fix: #3927: Error codes when starting/stopping

Daniel Tschlatscher d.tschlatscher at proxmox.com
Mon Mar 21 10:33:06 CET 2022


 containers Stopping and starting a container that is already in the desired
 state will not return an error value on the CLI anymore. The same as VMs do,
 when they are stopped but not running.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher at proxmox.com>
---
Changes from v2: return statements are now in the correct subroutines. 
 src/PVE/API2/LXC/Status.pm | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
index f7e3128..364db10 100644
--- a/src/PVE/API2/LXC/Status.pm
+++ b/src/PVE/API2/LXC/Status.pm
@@ -154,7 +154,7 @@ __PACKAGE__->register_method({
 	raise_param_exc({ skiplock => "Only root may use this option." })
 	    if $skiplock && $authuser ne 'root at pam';
 
-	die "CT $vmid already running\n" if PVE::LXC::check_running($vmid);
+	my $pid = PVE::LXC::check_running($vmid);
 
 	PVE::Cluster::check_cfs_quorum();
 
@@ -183,6 +183,8 @@ __PACKAGE__->register_method({
 		die "you can't start a CT if it's a template\n"
 		    if PVE::LXC::Config->is_template($conf);
 
+		return if $pid;			# Container is already running
+
 		if (!$skiplock && !PVE::LXC::Config->has_lock($conf, 'mounted')) {
 		    PVE::LXC::Config->check_lock($conf);
 		}
@@ -238,7 +240,7 @@ __PACKAGE__->register_method({
 	raise_param_exc({ skiplock => "Only root may use this option." })
 	    if $skiplock && $authuser ne 'root at pam';
 
-	die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid);
+	my $pid = PVE::LXC::check_running($vmid);
 
 	if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
 
@@ -260,6 +262,8 @@ __PACKAGE__->register_method({
 
 		syslog('info', "stopping CT $vmid: $upid\n");
 
+		return  if !$pid;
+
 		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






More information about the pve-devel mailing list