From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
Fiona Ebner <f.ebner@proxmox.com>
Subject: Re: [pve-devel] [PATCH common] systemd: add helper to cleanup transient unit
Date: Thu, 22 Jun 2023 14:56:04 +0200 [thread overview]
Message-ID: <59a4d52b-11a6-14d2-e675-4de9104773b7@proxmox.com> (raw)
In-Reply-To: <20230620150050.184347-1-f.ebner@proxmox.com>
Am 20/06/2023 um 17:00 schrieb Fiona Ebner:
> 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) = @_;
>
for the record, this the same in qemu-server directly for now, as talked off list,
didn't remembered that we got a run_command there already, still big thanks for
finding this!
prev parent reply other threads:[~2023-06-22 12:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Thomas Lamprecht [this message]
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=59a4d52b-11a6-14d2-e675-4de9104773b7@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=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