Blame SOURCES/0002-feat-enable-host-metering.service-on-rpm-installatio.patch

048fb3
From c3dace3c8655993572fc26f10c1e56f4cd2b8a23 Mon Sep 17 00:00:00 2001
048fb3
From: Petr Vobornik <pvoborni@redhat.com>
048fb3
Date: Mon, 8 Jan 2024 17:44:16 +0000
048fb3
Subject: [PATCH 1/2] feat: enable host-metering.service on rpm installation
048fb3
048fb3
Use systemd preset for enabling host-metering.
048fb3
048fb3
Refactor systemd calls to macros as recommended by packaging policy.
048fb3
048fb3
https://issues.redhat.com/browse/HMS-3358
048fb3
048fb3
Signed-off-by: Petr Vobornik <pvoborni@redhat.com>
048fb3
---
048fb3
 contrib/rpm/host-metering.spec.in       | 22 ++++++++--------------
048fb3
 contrib/systemd/80-host-metering.preset |  1 +
048fb3
 2 files changed, 9 insertions(+), 14 deletions(-)
048fb3
 create mode 100644 contrib/systemd/80-host-metering.preset
048fb3
048fb3
diff --git a/contrib/rpm/host-metering.spec.in b/contrib/rpm/host-metering.spec.in
048fb3
index 892afa038aeb1caea20e22ab94cff41e6942d1c3..06de45028f9e2163756f6ffc258eeae49c7f25a6 100644
048fb3
--- a/contrib/rpm/host-metering.spec.in
048fb3
+++ b/contrib/rpm/host-metering.spec.in
048fb3
@@ -78,6 +78,8 @@ install -m 0755 -vd                     %{buildroot}%{_bindir}
048fb3
 install -m 0755 -vp $(pwd)/bin/*        %{buildroot}%{_bindir}/
048fb3
 install -m 0755 -vd                     %{buildroot}%{_unitdir}
048fb3
 install -m 644 contrib/systemd/host-metering.service %{buildroot}%{_unitdir}/%{name}.service
048fb3
+install -m 0755 -vd                     %{buildroot}%{_presetdir}
048fb3
+install -m 644 contrib/systemd/80-host-metering.preset %{buildroot}%{_presetdir}/80-%{name}.preset
048fb3
 install -m 0755 -vd                     %{buildroot}%{_mandir}/man1
048fb3
 install -m 644 contrib/man/host-metering.1 %{buildroot}%{_mandir}/man1/host-metering.1
048fb3
 install -m 0755 -vd                     %{buildroot}%{_mandir}/man5
048fb3
@@ -91,7 +93,7 @@ install -D -p -m 644 contrib/selinux/%{modulename}.if %{buildroot}%{_datadir}/se
048fb3
 %endif
048fb3
 
048fb3
 %post
048fb3
-/bin/systemctl --system daemon-reload 2>&1 || :
048fb3
+%systemd_post %{name}.service
048fb3
 
048fb3
 %post selinux
048fb3
 %selinux_modules_install -s %{selinuxtype} %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp
048fb3
@@ -102,20 +104,11 @@ if [ "$1" -le "1" ]; then # First install
048fb3
    %systemd_postun_with_restart %{modulename}.service
048fb3
 fi
048fb3
 
048fb3
-%posttrans
048fb3
-# restart on upgrade if was enabled
048fb3
-/bin/systemctl is-enabled host-metering.service >/dev/null 2>&1
048fb3
-if [  $? -eq 0 ]; then
048fb3
-    /bin/systemctl restart host-metering.service >/dev/null || :
048fb3
-fi
048fb3
-
048fb3
-
048fb3
 %preun
048fb3
-# stop and disable on uninstallation
048fb3
-if [ $1 -eq 0 ]; then
048fb3
-    /bin/systemctl --quiet stop host-metering.service || :
048fb3
-    /bin/systemctl --quiet disable host-metering.service || :
048fb3
-fi
048fb3
+%systemd_preun %{name}.service
048fb3
+
048fb3
+%postun
048fb3
+%systemd_postun_with_restart %{name}.service
048fb3
 
048fb3
 %postun selinux
048fb3
 if [ $1 -eq 0 ]; then
048fb3
@@ -129,6 +122,7 @@ fi
048fb3
 %attr(644,root,root) %{_unitdir}/%{name}.service
048fb3
 %{_mandir}/man1/host-metering.1*
048fb3
 %{_mandir}/man5/host-metering.conf.5*
048fb3
+%{_presetdir}/*.preset
048fb3
 
048fb3
 %files selinux
048fb3
 %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp
048fb3
diff --git a/contrib/systemd/80-host-metering.preset b/contrib/systemd/80-host-metering.preset
048fb3
new file mode 100644
048fb3
index 0000000000000000000000000000000000000000..88677c10384bd104629a2e628e62032c99ed4f7a
048fb3
--- /dev/null
048fb3
+++ b/contrib/systemd/80-host-metering.preset
048fb3
@@ -0,0 +1 @@
048fb3
+enable host-metering.service
048fb3
-- 
048fb3
2.41.0
048fb3