It is already discussed in "[RFC] daemon: remove hardcode dep on libvirt-guests"
[1].
Mgmt can use means to save/restore domains on system shutdown/boot other then
libvirt-guests.service. Thus we need to specify appropriate ordering dependency between
libvirtd, domains and save/restore service. This patch takes approach suggested
in RFC and introduces a systemd target, so that ordering can be built next way:
libvirtd -> domain -> virt-guest-shutdown.target -> save-restore.service.
This way domains are decoupled from specific shutdown service via intermediate
target.
[1]
https://www.redhat.com/archives/libvir-list/2016-September/msg01353.html
---
daemon/Makefile.am | 4 ++++
daemon/virt-guest-shutdown.target | 3 +++
libvirt.spec.in | 1 +
src/util/virsystemd.c | 4 ++--
tools/libvirt-guests.service.in | 2 ++
5 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 daemon/virt-guest-shutdown.target
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 927d16f..463db6e 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -67,6 +67,7 @@ EXTRA_DIST = \
libvirt.rules \
libvirtd.sasl \
libvirtd.service.in \
+ virt-guest-shutdown.target \
libvirtd.sysconf \
libvirtd.sysctl \
libvirtd.aug \
@@ -456,8 +457,11 @@ install-init-systemd: install-sysconfig libvirtd.service
$(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
$(INSTALL_DATA) libvirtd.service \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/libvirtd.service
+ $(INSTALL_DATA) virt-guest-shutdown.target \
+ $(DESTDIR)$(SYSTEMD_UNIT_DIR)/virt-guest-shutdown.target
uninstall-init-systemd: uninstall-sysconfig
+ rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/virt-guest-shutdown.target
rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/libvirtd.service
rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || :
else ! LIBVIRT_INIT_SCRIPT_SYSTEMD
diff --git a/daemon/virt-guest-shutdown.target b/daemon/virt-guest-shutdown.target
new file mode 100644
index 0000000..bf87652
--- /dev/null
+++ b/daemon/virt-guest-shutdown.target
@@ -0,0 +1,3 @@
+[Unit]
+Description=Libvirt guests shutdown
+Documentation=http://libvirt.org
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 00b95b8..82a7363 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1579,6 +1579,7 @@ exit 0
%if %{with_systemd}
%{_unitdir}/libvirtd.service
+%{_unitdir}/virt-guest-shutdown.target
%{_unitdir}/virtlogd.service
%{_unitdir}/virtlogd.socket
%{_unitdir}/virtlockd.service
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 604dcdd..c8837f9 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -370,7 +370,7 @@ int virSystemdCreateMachine(const char *name,
3,
"Slice", "s", slicename,
"After", "as", 1,
"libvirtd.service",
- "Before", "as", 1,
"libvirt-guests.service") < 0)
+ "Before", "as", 1,
"virt-guest-shutdown.target") < 0)
goto cleanup;
if (error.level == VIR_ERR_ERROR) {
@@ -411,7 +411,7 @@ int virSystemdCreateMachine(const char *name,
3,
"Slice", "s", slicename,
"After", "as", 1,
"libvirtd.service",
- "Before", "as", 1,
"libvirt-guests.service") < 0)
+ "Before", "as", 1,
"virt-guest-shutdown.target") < 0)
goto cleanup;
}
diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
index b4f54f2..d0ba655 100644
--- a/tools/libvirt-guests.service.in
+++ b/tools/libvirt-guests.service.in
@@ -1,9 +1,11 @@
[Unit]
Description=Suspend/Resume Running libvirt Guests
Requires=libvirtd.service
+Requires=virt-guest-shutdown.target
After=network.target
After=time-sync.target
After=libvirtd.service
+After=virt-guest-shutdown.target
Documentation=man:libvirtd(8)
Documentation=http://libvirt.org
--
1.8.3.1