From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 7757A712C2 for ; Wed, 7 Apr 2021 16:03:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 619461139A for ; Wed, 7 Apr 2021 16:02:36 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id EEFEC11384 for ; Wed, 7 Apr 2021 16:02:34 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9562B459F5; Wed, 7 Apr 2021 16:02:34 +0200 (CEST) From: Dylan Whyte To: pbs-devel@lists.proxmox.com Cc: dylan Date: Wed, 7 Apr 2021 16:02:28 +0200 Message-Id: <20210407140228.32382-1-d.whyte@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [vzdump.pm] Subject: [pbs-devel] [PATCH] fix #3369: auto-start vms after failed pbs backup X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Apr 2021 14:03:06 -0000 From: dylan Fixes an issue in which a VM fails to automatically restart after a failed stop-mode backup to pbs. Signed-off-by: Dylan Whyte --- Notes: 1. The 1sec time delay was needed, as the check to see if the VM is running was still true while this code was executed (although the vm was just about to stop) 2. The previously used vm_status call just checks if a PID exists and returns true if so. This also returns true when the VM is in "prelauch" state, hence PVE::QemuServer::vmstatus was used to see the exact state and handle the situation accordingly. Otherwise, the VM gets stuck in prelauch state from time to time. PVE/VZDump.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm index fb4c8bad..1bda1f15 100644 --- a/PVE/VZDump.pm +++ b/PVE/VZDump.pm @@ -23,6 +23,7 @@ use PVE::VZDump::Common; use PVE::VZDump::Plugin; use PVE::Tools qw(extract_param split_list); use PVE::API2Tools; +use PVE::QemuServer; my @posix_filesystems = qw(ext3 ext4 nfs nfs4 reiserfs xfs); @@ -1039,10 +1040,17 @@ sub exec_backup_task { debugmsg ('info', "resume vm", $logfd); $plugin->resume_vm ($task, $vmid); } else { - my $running = $plugin->vm_status($vmid); - if (!$running) { + sleep(1); + my $vmstatus = PVE::QemuServer::vmstatus($vmid, 1); + my $stat = $vmstatus->{$vmid}; + my $status = $stat->{qmpstatus}; + + if ($status eq "stopped") { + $plugin->start_vm ($task, $vmid); + debugmsg ('info', "restarting vm", $logfd); + } elsif ($status eq "prelaunch") { + $plugin->resume_vm ($task, $vmid); debugmsg ('info', "restarting vm", $logfd); - $plugin->start_vm ($task, $vmid); } } $self->run_hook_script ('post-restart', $task, $logfd); -- 2.20.1