[PATCH] libvirt-guests.service: use Type=exec

Antonio Terceiro posted 1 patch 2 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20251222174633.13552-1-terceiro@debian.org
tools/libvirt-guests.service.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] libvirt-guests.service: use Type=exec
Posted by Antonio Terceiro 2 weeks, 1 day ago
Type=oneshot means that the service is only considered started after the
main process exits. In setups where libvirt-guests is configured to be
used and imposes a delay on the startup of guests, this will cause
systemd to report a quite high boot time as it will wait until all
guests have booted, plus all the delay between them. High boot times are
often reported as issues in monitoring systems, and require operator
attention, while in this case there is not really an issue with the
system, it's just doing what it was configured to do.

With Type=exec, the service is considered started right after the main
process is *started*, but the boot process will not wait for it.

Having other units depend on libvirt-guests.service finishing was
already not reliable because one cannot know how long the OS inside each
guest takes to boot, and libvirt-guests already does not wait for them
to be in any particular state.

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
---
 tools/libvirt-guests.service.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
index b044444298..c8e4d3d749 100644
--- a/tools/libvirt-guests.service.in
+++ b/tools/libvirt-guests.service.in
@@ -19,7 +19,7 @@ EnvironmentFile=-@initconfdir@/libvirt-guests
 # out the code
 ExecStart=@libexecdir@/libvirt-guests.sh start
 ExecStop=@libexecdir@/libvirt-guests.sh stop
-Type=oneshot
+Type=exec
 RemainAfterExit=yes
 StandardOutput=journal+console
 TimeoutStopSec=0
-- 
2.51.0
Re: [PATCH] libvirt-guests.service: use Type=exec
Posted by Christian Ehrhardt via Devel 17 hours ago
On Mon, Jan 5, 2026 at 9:58 AM Antonio Terceiro <terceiro@debian.org> wrote:
>
> Type=oneshot means that the service is only considered started after the
> main process exits. In setups where libvirt-guests is configured to be
> used and imposes a delay on the startup of guests, this will cause
> systemd to report a quite high boot time as it will wait until all
> guests have booted, plus all the delay between them. High boot times are
> often reported as issues in monitoring systems, and require operator
> attention, while in this case there is not really an issue with the
> system, it's just doing what it was configured to do.
>
> With Type=exec, the service is considered started right after the main
> process is *started*, but the boot process will not wait for it.
>
> Having other units depend on libvirt-guests.service finishing was
> already not reliable because one cannot know how long the OS inside each
> guest takes to boot, and libvirt-guests already does not wait for them
> to be in any particular state.
>
> Signed-off-by: Antonio Terceiro <terceiro@debian.org>
> ---
>  tools/libvirt-guests.service.in | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
> index b044444298..c8e4d3d749 100644
> --- a/tools/libvirt-guests.service.in
> +++ b/tools/libvirt-guests.service.in
> @@ -19,7 +19,7 @@ EnvironmentFile=-@initconfdir@/libvirt-guests
>  # out the code
>  ExecStart=@libexecdir@/libvirt-guests.sh start
>  ExecStop=@libexecdir@/libvirt-guests.sh stop

Hi Antonio,
sorry, I only saw this fly by and wondered.
Not about the discussion so far, that was about start and there it is fine.

But doesn't this change make the stop action to not wait until all
guests are shut down in a good way and instead pull the rug under
their feet?
There (on shutdown) - we want it to wait for sure, make it slow until
it is done or times out.

I think the change would somehow need to split the behavior between
start/stop to not cause regressions - WDYT?

> -Type=oneshot
> +Type=exec
>  RemainAfterExit=yes
>  StandardOutput=journal+console
>  TimeoutStopSec=0
> --
> 2.51.0
>


-- 
Christian Ehrhardt
Director of Engineering, Ubuntu Server
Canonical Ltd
Re: [PATCH] libvirt-guests.service: use Type=exec
Posted by Daniel P. Berrangé via Devel 16 hours ago
On Tue, Jan 06, 2026 at 03:25:03PM +0100, Christian Ehrhardt via Devel wrote:
> On Mon, Jan 5, 2026 at 9:58 AM Antonio Terceiro <terceiro@debian.org> wrote:
> >
> > Type=oneshot means that the service is only considered started after the
> > main process exits. In setups where libvirt-guests is configured to be
> > used and imposes a delay on the startup of guests, this will cause
> > systemd to report a quite high boot time as it will wait until all
> > guests have booted, plus all the delay between them. High boot times are
> > often reported as issues in monitoring systems, and require operator
> > attention, while in this case there is not really an issue with the
> > system, it's just doing what it was configured to do.
> >
> > With Type=exec, the service is considered started right after the main
> > process is *started*, but the boot process will not wait for it.
> >
> > Having other units depend on libvirt-guests.service finishing was
> > already not reliable because one cannot know how long the OS inside each
> > guest takes to boot, and libvirt-guests already does not wait for them
> > to be in any particular state.
> >
> > Signed-off-by: Antonio Terceiro <terceiro@debian.org>
> > ---
> >  tools/libvirt-guests.service.in | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
> > index b044444298..c8e4d3d749 100644
> > --- a/tools/libvirt-guests.service.in
> > +++ b/tools/libvirt-guests.service.in
> > @@ -19,7 +19,7 @@ EnvironmentFile=-@initconfdir@/libvirt-guests
> >  # out the code
> >  ExecStart=@libexecdir@/libvirt-guests.sh start
> >  ExecStop=@libexecdir@/libvirt-guests.sh stop
> 
> Hi Antonio,
> sorry, I only saw this fly by and wondered.
> Not about the discussion so far, that was about start and there it is fine.
> 
> But doesn't this change make the stop action to not wait until all
> guests are shut down in a good way and instead pull the rug under
> their feet?
> There (on shutdown) - we want it to wait for sure, make it slow until
> it is done or times out.
> 
> I think the change would somehow need to split the behavior between
> start/stop to not cause regressions - WDYT?

I checked the systemd source before merging and AFAICT, the 'exec' vs
'oneshot' distinction doesn't affect the shutdown ordering or waiting
behaviour, only the startup behaviour, so it should still be ok.

> 
> > -Type=oneshot
> > +Type=exec
> >  RemainAfterExit=yes
> >  StandardOutput=journal+console
> >  TimeoutStopSec=0
> > --

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: [PATCH] libvirt-guests.service: use Type=exec
Posted by Daniel P. Berrangé via Devel 1 day, 14 hours ago
On Mon, Dec 22, 2025 at 02:46:33PM -0300, Antonio Terceiro wrote:
> Type=oneshot means that the service is only considered started after the
> main process exits. In setups where libvirt-guests is configured to be
> used and imposes a delay on the startup of guests, this will cause
> systemd to report a quite high boot time as it will wait until all
> guests have booted, plus all the delay between them. High boot times are
> often reported as issues in monitoring systems, and require operator
> attention, while in this case there is not really an issue with the
> system, it's just doing what it was configured to do.
> 
> With Type=exec, the service is considered started right after the main
> process is *started*, but the boot process will not wait for it.
> 
> Having other units depend on libvirt-guests.service finishing was
> already not reliable because one cannot know how long the OS inside each
> guest takes to boot, and libvirt-guests already does not wait for them
> to be in any particular state.

The dependencies on libvirt-guest.service don't neccessarily need to
care about what the guest OS is doing, they might merely want to delay
interaction with libvirt until all guests have been auto-started. eg
so they don't try to start other guests while auto-start is still
running. So there's still a possibility of regression in behaviour in
this regard.

On the other hand, we recently introduced built-in support for autostart
in the virtqemud/libvirtd daemons which is intended to obsolete use of
the libvirt-guests.service script. The built-in  support has closer
conceptual behaviour in that it runs asynchronously once systemd has
started virtqemud, so no other system service can co-ordinate against
autostart directly.

We originally added Type=oneshot in

commit 79ca7e4e5763795b041e95738c73d4e64bf1024b
Author: Gerd v. Egidy <gerd@egidy.de>
Date:   Fri Jul 27 17:01:04 2012 +0200

    libvirt-guests: systemd host shutdown does not work

but looking at that commit, AFAICT, it was the RemainAfterExit=yes
line that was the actual fix. That is valid to use with Type=exec
too, so we didn't need the change to 'oneshot' IIUC

> 
> Signed-off-by: Antonio Terceiro <terceiro@debian.org>
> ---
>  tools/libvirt-guests.service.in | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
> index b044444298..c8e4d3d749 100644
> --- a/tools/libvirt-guests.service.in
> +++ b/tools/libvirt-guests.service.in
> @@ -19,7 +19,7 @@ EnvironmentFile=-@initconfdir@/libvirt-guests
>  # out the code
>  ExecStart=@libexecdir@/libvirt-guests.sh start
>  ExecStop=@libexecdir@/libvirt-guests.sh stop
> -Type=oneshot
> +Type=exec
>  RemainAfterExit=yes
>  StandardOutput=journal+console
>  TimeoutStopSec=0
> -- 
> 2.51.0
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [PATCH] libvirt-guests.service: use Type=exec
Posted by Daniel P. Berrangé via Devel 18 hours ago
On Mon, Jan 05, 2026 at 04:57:02PM +0000, Daniel P. Berrangé via Devel wrote:
> On Mon, Dec 22, 2025 at 02:46:33PM -0300, Antonio Terceiro wrote:
> > Type=oneshot means that the service is only considered started after the
> > main process exits. In setups where libvirt-guests is configured to be
> > used and imposes a delay on the startup of guests, this will cause
> > systemd to report a quite high boot time as it will wait until all
> > guests have booted, plus all the delay between them. High boot times are
> > often reported as issues in monitoring systems, and require operator
> > attention, while in this case there is not really an issue with the
> > system, it's just doing what it was configured to do.
> > 
> > With Type=exec, the service is considered started right after the main
> > process is *started*, but the boot process will not wait for it.
> > 
> > Having other units depend on libvirt-guests.service finishing was
> > already not reliable because one cannot know how long the OS inside each
> > guest takes to boot, and libvirt-guests already does not wait for them
> > to be in any particular state.
> 
> The dependencies on libvirt-guest.service don't neccessarily need to
> care about what the guest OS is doing, they might merely want to delay
> interaction with libvirt until all guests have been auto-started. eg
> so they don't try to start other guests while auto-start is still
> running. So there's still a possibility of regression in behaviour in
> this regard.
> 
> On the other hand, we recently introduced built-in support for autostart
> in the virtqemud/libvirtd daemons which is intended to obsolete use of
> the libvirt-guests.service script. The built-in  support has closer
> conceptual behaviour in that it runs asynchronously once systemd has
> started virtqemud, so no other system service can co-ordinate against
> autostart directly.
> 
> We originally added Type=oneshot in
> 
> commit 79ca7e4e5763795b041e95738c73d4e64bf1024b
> Author: Gerd v. Egidy <gerd@egidy.de>
> Date:   Fri Jul 27 17:01:04 2012 +0200
> 
>     libvirt-guests: systemd host shutdown does not work
> 
> but looking at that commit, AFAICT, it was the RemainAfterExit=yes
> line that was the actual fix. That is valid to use with Type=exec
> too, so we didn't need the change to 'oneshot' IIUC

Anyway

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

and I've merged this fix.

> 
> > 
> > Signed-off-by: Antonio Terceiro <terceiro@debian.org>
> > ---
> >  tools/libvirt-guests.service.in | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
> > index b044444298..c8e4d3d749 100644
> > --- a/tools/libvirt-guests.service.in
> > +++ b/tools/libvirt-guests.service.in
> > @@ -19,7 +19,7 @@ EnvironmentFile=-@initconfdir@/libvirt-guests
> >  # out the code
> >  ExecStart=@libexecdir@/libvirt-guests.sh start
> >  ExecStop=@libexecdir@/libvirt-guests.sh stop
> > -Type=oneshot
> > +Type=exec
> >  RemainAfterExit=yes
> >  StandardOutput=journal+console
> >  TimeoutStopSec=0
> > -- 
> > 2.51.0
> > 
> 
> With regards,
> Daniel
> -- 
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|