Blob Blame History Raw
From c3dace3c8655993572fc26f10c1e56f4cd2b8a23 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvoborni@redhat.com>
Date: Mon, 8 Jan 2024 17:44:16 +0000
Subject: [PATCH 1/2] feat: enable host-metering.service on rpm installation

Use systemd preset for enabling host-metering.

Refactor systemd calls to macros as recommended by packaging policy.

https://issues.redhat.com/browse/HMS-3358

Signed-off-by: Petr Vobornik <pvoborni@redhat.com>
---
 contrib/rpm/host-metering.spec.in       | 22 ++++++++--------------
 contrib/systemd/80-host-metering.preset |  1 +
 2 files changed, 9 insertions(+), 14 deletions(-)
 create mode 100644 contrib/systemd/80-host-metering.preset

diff --git a/contrib/rpm/host-metering.spec.in b/contrib/rpm/host-metering.spec.in
index 892afa038aeb1caea20e22ab94cff41e6942d1c3..06de45028f9e2163756f6ffc258eeae49c7f25a6 100644
--- a/contrib/rpm/host-metering.spec.in
+++ b/contrib/rpm/host-metering.spec.in
@@ -78,6 +78,8 @@ install -m 0755 -vd                     %{buildroot}%{_bindir}
 install -m 0755 -vp $(pwd)/bin/*        %{buildroot}%{_bindir}/
 install -m 0755 -vd                     %{buildroot}%{_unitdir}
 install -m 644 contrib/systemd/host-metering.service %{buildroot}%{_unitdir}/%{name}.service
+install -m 0755 -vd                     %{buildroot}%{_presetdir}
+install -m 644 contrib/systemd/80-host-metering.preset %{buildroot}%{_presetdir}/80-%{name}.preset
 install -m 0755 -vd                     %{buildroot}%{_mandir}/man1
 install -m 644 contrib/man/host-metering.1 %{buildroot}%{_mandir}/man1/host-metering.1
 install -m 0755 -vd                     %{buildroot}%{_mandir}/man5
@@ -91,7 +93,7 @@ install -D -p -m 644 contrib/selinux/%{modulename}.if %{buildroot}%{_datadir}/se
 %endif
 
 %post
-/bin/systemctl --system daemon-reload 2>&1 || :
+%systemd_post %{name}.service
 
 %post selinux
 %selinux_modules_install -s %{selinuxtype} %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp
@@ -102,20 +104,11 @@ if [ "$1" -le "1" ]; then # First install
    %systemd_postun_with_restart %{modulename}.service
 fi
 
-%posttrans
-# restart on upgrade if was enabled
-/bin/systemctl is-enabled host-metering.service >/dev/null 2>&1
-if [  $? -eq 0 ]; then
-    /bin/systemctl restart host-metering.service >/dev/null || :
-fi
-
-
 %preun
-# stop and disable on uninstallation
-if [ $1 -eq 0 ]; then
-    /bin/systemctl --quiet stop host-metering.service || :
-    /bin/systemctl --quiet disable host-metering.service || :
-fi
+%systemd_preun %{name}.service
+
+%postun
+%systemd_postun_with_restart %{name}.service
 
 %postun selinux
 if [ $1 -eq 0 ]; then
@@ -129,6 +122,7 @@ fi
 %attr(644,root,root) %{_unitdir}/%{name}.service
 %{_mandir}/man1/host-metering.1*
 %{_mandir}/man5/host-metering.conf.5*
+%{_presetdir}/*.preset
 
 %files selinux
 %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp
diff --git a/contrib/systemd/80-host-metering.preset b/contrib/systemd/80-host-metering.preset
new file mode 100644
index 0000000000000000000000000000000000000000..88677c10384bd104629a2e628e62032c99ed4f7a
--- /dev/null
+++ b/contrib/systemd/80-host-metering.preset
@@ -0,0 +1 @@
+enable host-metering.service
-- 
2.41.0