diff mbox series

[2/3] spec: avoid repeated calls to systemd macros and binaries

Message ID 20210625180954.454141-3-berrange@redhat.com
State New
Headers show
Series [1/3] spec: drop/update dependencies on systemd-{units, sysv} | expand

Commit Message

Daniel P. Berrangé June 25, 2021, 6:09 p.m. UTC
From: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>


The macro can take multiple arguments, and the calls are more efficient
if done in one go.

Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>

---
 libvirt.spec.in | 50 +++++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 22 deletions(-)

-- 
2.31.1
diff mbox series

Patch

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 7f12a92b7f..39226175ce 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1257,31 +1257,35 @@  getent group libvirt >/dev/null || groupadd -r libvirt
 exit 0
 
 %post daemon
+%global post_units \\\
+        virtlockd.socket virtlockd-admin.socket \\\
+        virtlogd.socket virtlogd-admin.socket \\\
+        libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket \\\
+        libvirtd-tcp.socket libvirtd-tls.socket \\\
+        libvirtd.service \\\
+        libvirt-guests.service
 
-%systemd_post virtlockd.socket virtlockd-admin.socket
-%systemd_post virtlogd.socket virtlogd-admin.socket
-%systemd_post libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket
-%systemd_post libvirtd-tcp.socket libvirtd-tls.socket
-%systemd_post libvirtd.service
-%systemd_post libvirt-guests.service
+%systemd_post %post_units
 
 # request daemon restart in posttrans
 mkdir -p %{_localstatedir}/lib/rpm-state/libvirt || :
 touch %{_localstatedir}/lib/rpm-state/libvirt/restart || :
 
 %preun daemon
-%systemd_preun libvirtd.service
-%systemd_preun libvirtd-tcp.socket libvirtd-tls.socket
-%systemd_preun libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket
-%systemd_preun virtlogd.socket virtlogd-admin.socket virtlogd.service
-%systemd_preun virtlockd.socket virtlockd-admin.socket virtlockd.service
-%systemd_preun libvirt-guests.service
+%global preun_units \\\
+        libvirtd.service \\\
+        libvirtd-tcp.socket libvirtd-tls.socket \\\
+        libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket \\\
+        virtlogd.socket virtlogd-admin.socket virtlogd.service \\\
+        virtlockd.socket virtlockd-admin.socket virtlockd.service \\\
+        libvirt-guests.service
+
+%systemd_preun %preun_units
 
 %postun daemon
 /bin/systemctl daemon-reload >/dev/null 2>&1 || :
 if [ $1 -ge 1 ] ; then
-    /bin/systemctl reload-or-try-restart virtlockd.service >/dev/null 2>&1 || :
-    /bin/systemctl reload-or-try-restart virtlogd.service >/dev/null 2>&1 || :
+    /bin/systemctl reload-or-try-restart virtlockd.service virtlogd.service >/dev/null 2>&1 || :
 fi
 %systemd_postun libvirt-guests.service
 
@@ -1308,11 +1312,12 @@  if [ -f %{_localstatedir}/lib/rpm-state/libvirt/restart ]; then
         # systemd socket activation, because switching things
         # might confuse mgmt tool like puppet/ansible that
         # expect the old style libvirtd
-        /bin/systemctl mask libvirtd.socket >/dev/null 2>&1 || :
-        /bin/systemctl mask libvirtd-ro.socket >/dev/null 2>&1 || :
-        /bin/systemctl mask libvirtd-admin.socket >/dev/null 2>&1 || :
-        /bin/systemctl mask libvirtd-tls.socket >/dev/null 2>&1 || :
-        /bin/systemctl mask libvirtd-tcp.socket >/dev/null 2>&1 || :
+        /bin/systemctl mask \
+                libvirtd.socket \
+                libvirtd-ro.socket \
+                libvirtd-admin.socket \
+                libvirtd-tls.socket \
+                libvirtd-tcp.socket >/dev/null 2>&1 || :
     else
         # Old libvirtd owns the sockets and will delete them on
         # shutdown. Can't use a try-restart as libvirtd will simply
@@ -1324,9 +1329,10 @@  if [ -f %{_localstatedir}/lib/rpm-state/libvirt/restart ]; then
         then
             /bin/systemctl stop libvirtd.service >/dev/null 2>&1 || :
 
-            /bin/systemctl try-restart libvirtd.socket >/dev/null 2>&1 || :
-            /bin/systemctl try-restart libvirtd-ro.socket >/dev/null 2>&1 || :
-            /bin/systemctl try-restart libvirtd-admin.socket >/dev/null 2>&1 || :
+            /bin/systemctl try-restart \
+                    libvirtd.socket \
+                    libvirtd-ro.socket \
+                    libvirtd-admin.socket >/dev/null 2>&1 || :
 
             /bin/systemctl start libvirtd.service >/dev/null 2>&1 || :
         fi