public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common] systemd: add helper to cleanup transient unit
Date: Tue, 20 Jun 2023 17:00:49 +0200	[thread overview]
Message-ID: <20230620150050.184347-1-f.ebner@proxmox.com> (raw)

which combines the stop+wait logic previously present at the single
call site of wait_for_unit_removed() in QemuServer.pm. It also does a
reset-failed call first, to ensure a unit in a failed state is also
cleaned up properly.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/Systemd.pm | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm
index 2517d31..327106f 100644
--- a/src/PVE/Systemd.pm
+++ b/src/PVE/Systemd.pm
@@ -7,7 +7,7 @@ use Net::DBus qw(dbus_uint32 dbus_uint64 dbus_boolean);
 use Net::DBus::Callback;
 use Net::DBus::Reactor;
 
-use PVE::Tools qw(file_set_contents file_get_contents trim);
+use PVE::Tools qw(file_set_contents file_get_contents run_command trim);
 
 sub escape_unit {
     my ($val, $is_path) = @_;
@@ -167,6 +167,20 @@ sub wait_for_unit_removed($;$) {
     }, $timeout);
 }
 
+sub cleanup_transient_unit($;$) {
+    my ($unit, $timeout) = @_;
+
+    eval {
+	my %param = ( outfunc => sub {}, errfunc => sub {} );
+	# If the unit is in a failed state (e.g. after being OOM-killed), stopping is not enough.
+	run_command(['/bin/systemctl', 'reset-failed', $unit], %param);
+	run_command(['/bin/systemctl', 'stop', $unit], %param);
+    };
+
+    # Issues with the above not being fully completed are rare, but not impossible, see bug #3733.
+    wait_for_unit_removed($unit, $timeout);
+}
+
 sub read_ini {
     my ($filename) = @_;
 
-- 
2.39.2





             reply	other threads:[~2023-06-20 15:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 15:00 Fiona Ebner [this message]
2023-06-20 15:00 ` [pve-devel] [PATCH qemu-server] vm start: switch to new cleanup_transient_unit systemd helper Fiona Ebner
2023-06-22 12:56 ` [pve-devel] [PATCH common] systemd: add helper to cleanup transient unit Thomas Lamprecht

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=20230620150050.184347-1-f.ebner@proxmox.com \
    --to=f.ebner@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