44173a
From ee1ce580f5373070e4b6a50d1ae4a3218c737a72 Mon Sep 17 00:00:00 2001
44173a
Message-Id: <ee1ce580f5373070e4b6a50d1ae4a3218c737a72@dist-git>
44173a
From: Martin Kletzander <mkletzan@redhat.com>
44173a
Date: Mon, 14 Feb 2022 12:37:37 +0100
44173a
Subject: [PATCH] Make systemd unit ordering more robust
44173a
44173a
Since libvirt-guests script/service can operate on various URIs and we do
44173a
support both socket activation and traditional services, the ordering should be
44173a
specified for all the possible sockets and services.
44173a
44173a
Also remove the Wants= dependency since do not want to start any service.  We
44173a
cannot know which one libvirt-guests is configured, so we'd have to start all
44173a
the daemons which would break if unused colliding services are not
44173a
masked (libvirtd.service in the modular case and all the modular daemon service
44173a
units in the monolithic scenario).  Fortunately we can assume that the system is
44173a
configured properly to start services/sockets that are of interest to the user.
44173a
That also works with the setup described in https://libvirt.org/daemons.html .
44173a
44173a
To make it even more robust we add the daemon service into the machine units
44173a
created for individual domains as it was missing there.
44173a
44173a
https://bugzilla.redhat.com/show_bug.cgi?id=1868537
44173a
44173a
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
44173a
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
44173a
(cherry picked from commit 4e42686adef8b9e9266f0099ddcd25bc95c4ed43)
44173a
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
44173a
---
44173a
 src/util/virsystemd.c           |  8 ++++++--
44173a
 tools/libvirt-guests.service.in | 12 +++++++++++-
44173a
 2 files changed, 17 insertions(+), 3 deletions(-)
44173a
44173a
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
44173a
index a86d4c6bb9..f156c2f39a 100644
44173a
--- a/src/util/virsystemd.c
44173a
+++ b/src/util/virsystemd.c
44173a
@@ -441,8 +441,10 @@ int virSystemdCreateMachine(const char *name,
44173a
                                                 nicindexes, nnicindexes, sizeof(int));
44173a
         gprops = g_variant_new_parsed("[('Slice', <%s>),"
44173a
                                       " ('After', <['libvirtd.service']>),"
44173a
+                                      " ('After', <['virt%sd.service']>),"
44173a
                                       " ('Before', <['virt-guest-shutdown.target']>)]",
44173a
-                                      slicename);
44173a
+                                      slicename,
44173a
+                                      drivername);
44173a
         message = g_variant_new("(s@ayssus@ai@a(sv))",
44173a
                                 name,
44173a
                                 guuid,
44173a
@@ -489,8 +491,10 @@ int virSystemdCreateMachine(const char *name,
44173a
                                           uuid, 16, sizeof(unsigned char));
44173a
         gprops = g_variant_new_parsed("[('Slice', <%s>),"
44173a
                                       " ('After', <['libvirtd.service']>),"
44173a
+                                      " ('After', <['virt%sd.service']>),"
44173a
                                       " ('Before', <['virt-guest-shutdown.target']>)]",
44173a
-                                      slicename);
44173a
+                                      slicename,
44173a
+                                      drivername);
44173a
         message = g_variant_new("(s@ayssus@a(sv))",
44173a
                                 name,
44173a
                                 guuid,
44173a
diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
44173a
index 1a9b233e11..3cf6476196 100644
44173a
--- a/tools/libvirt-guests.service.in
44173a
+++ b/tools/libvirt-guests.service.in
44173a
@@ -1,10 +1,20 @@
44173a
 [Unit]
44173a
 Description=Suspend/Resume Running libvirt Guests
44173a
-Wants=libvirtd.service
44173a
 Requires=virt-guest-shutdown.target
44173a
 After=network.target
44173a
 After=time-sync.target
44173a
+After=libvirtd.socket
44173a
+After=virtqemud.socket
44173a
+After=virtlxcd.socket
44173a
+After=virtvboxd.socket
44173a
+After=virtvzd.socket
44173a
+After=virtxend.socket
44173a
 After=libvirtd.service
44173a
+After=virtqemud.service
44173a
+After=virtlxcd.service
44173a
+After=virtvboxd.service
44173a
+After=virtvzd.service
44173a
+After=virtxend.service
44173a
 After=virt-guest-shutdown.target
44173a
 Documentation=man:libvirt-guests(8)
44173a
 Documentation=https://libvirt.org
44173a
-- 
44173a
2.35.1
44173a