Skip to content

Commit

Permalink
feat: enable host-metering.service on rpm installation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pvoborni committed Jan 8, 2024
1 parent a14d76f commit c3dace3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
22 changes: 8 additions & 14 deletions contrib/rpm/host-metering.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions contrib/systemd/80-host-metering.preset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable host-metering.service

0 comments on commit c3dace3

Please sign in to comment.