all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common] systemd: add helper to cleanup transient unit
@ 2023-06-20 15:00 Fiona Ebner
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Fiona Ebner @ 2023-06-20 15:00 UTC (permalink / raw)
  To: pve-devel

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-22 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 15:00 [pve-devel] [PATCH common] systemd: add helper to cleanup transient unit Fiona Ebner
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal