Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

57 changes: 45 additions & 12 deletions packages/client/katello-host-tools/katello-host-tools.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
%global zypper_install (0%{?suse_version} > 0)
%global build_tracer 0%{?rhel} >= 7 || 0%{?fedora} || 0%{?suse_version}

%if 0%{?suse_version}
%define pkg_systemd_post() %service_add_post %{*}
%define pkg_systemd_preun() %service_del_preun %{*}
%define pkg_systemd_postun() %service_del_postun %{*}
%else
%define pkg_systemd_post() %systemd_post %{*}
%define pkg_systemd_preun() %systemd_preun %{*}
%define pkg_systemd_postun() %systemd_postun %{*}
%endif
Comment on lines +6 to +14

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
%if 0%{?suse_version}
%define pkg_systemd_post() %service_add_post %{*}
%define pkg_systemd_preun() %service_del_preun %{*}
%define pkg_systemd_postun() %service_del_postun %{*}
%else
%define pkg_systemd_post() %systemd_post %{*}
%define pkg_systemd_preun() %systemd_preun %{*}
%define pkg_systemd_postun() %systemd_postun %{*}
%endif
%if 0%{?suse_version}
%define pkg_systemd_post() %service_add_post %{*}
%define pkg_systemd_preun() %service_del_preun %{*}
%define pkg_systemd_postun() %service_del_postun %{*}
%define pkg_systemd_postun_with_restart() %service_del_postun %{*}
%else
%define pkg_systemd_post() %systemd_post %{*}
%define pkg_systemd_preun() %systemd_preun %{*}
%define pkg_systemd_postun() %systemd_postun %{*}
%define pkg_systemd_postun_with_restart() %systemd_postun_with_restart %{*}
%endif

On Fedora, %systemd_postun expands to literally nothing (verified from /usr/lib/rpm/macros.d/macros.systemd). This means on package upgrade ($1 >= 1), the timer won't be restarted to pick up changes.

# From /usr/lib/rpm/macros.d/macros.systemd on Fedora 43:

%systemd_postun() \
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun}} \
%{nil}

%systemd_postun_with_restart() \
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \
if [ $1 -ge 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then \
    # Package upgrade, not uninstall \
    /usr/lib/systemd/systemd-update-helper mark-restart-system-units %{?*} || : \
fi \
%{nil}

Compare with plocate which uses %systemd_postun_with_restart — that calls systemd-update-helper mark-restart-system-units, which sets a Markers=+needs-restart flag on the unit. The actual restart is then performed by a transfiletriggerin from the systemd package, which runs systemd-update-helper system-reload-restart (daemon-reload + systemctl reload-or-restart --marked) whenever files in /usr/lib/systemd/system/ are added or updated.

For the SUSE compat wrapper this would need a corresponding %service_del_postun_with_restart or equivalent — worth checking if SUSE has one, or whether a manual systemctl try-restart is needed there.

Two real-world examples from Fedora rawhide:

plocate (src):

%postun
%systemd_postun_with_restart plocate-updatedb.service plocate-updatedb.timer

util-linux / fstrim (src):

%postun
%systemd_postun_with_restart fstrim.timer
%systemd_postun fstrim.service

Note util-linux uses _with_restart on the timer but plain %systemd_postun (no-op) on the service — they want the timer restarted on upgrade but don't care about restarting the one-shot service itself. Reasonable pattern for katello-tracer-upload too since it's also a one-shot triggered by timer.


%if 0%{?suse_version}
%define dist suse%{?suse_version}
%endif
Expand Down Expand Up @@ -33,8 +43,8 @@
%global katello_libdir %{python_libdir}/katello

Name: katello-host-tools
Version: 4.5.0
Release: 2%{?dist}
Version: 4.6.0
Release: 1%{?dist}
Summary: A set of commands and yum plugins that support a Katello host
Group: Development/Languages
%if 0%{?suse_version}
Expand All @@ -54,6 +64,8 @@ BuildArch: noarch
%endif

Requires: subscription-manager
Requires: systemd
BuildRequires: systemd-rpm-macros systemd
Obsoletes: %{name}-fact-plugin < %{version}-%{release}
Obsoletes: katello-agent < %{version}-%{release}

Expand Down Expand Up @@ -98,11 +110,6 @@ BuildArch: noarch
Summary: Adds Tracer functionality to a client managed by katello-host-tools
Group: Development/Languages
Requires: %{name} = %{version}-%{release}
%if 0%{?suse_version}
Requires: cronie
%else
Requires: crontabs
%endif
%if %{yum_install}
Requires: python2-tracer >= 0.6.12
%endif
Expand Down Expand Up @@ -208,9 +215,12 @@ mkdir -p %{buildroot}%{_sbindir}
cp extra/katello-tracer-upload-dnf %{buildroot}%{_sbindir}/katello-tracer-upload
%endif

# crontab
mkdir -p %{buildroot}%{_sysconfdir}/cron.d/
cp extra/katello-tracer-upload.cron %{buildroot}%{_sysconfdir}/cron.d/katello-tracer-upload
# tracer systemd service and timer
install -Dp -m0644 extra/katello-tracer-upload.service.in %{buildroot}%{_unitdir}/katello-tracer-upload.service
install -Dp -m0644 extra/katello-tracer-upload.timer %{buildroot}%{_unitdir}/katello-tracer-upload.timer
Comment on lines -213 to +220

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With cron, you just drop a file to a location and you're done. With systemd timers, you drop the unit definitions, but you then have to enable them. How would that be handled?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure as I'm not yet able to fully test this but I have expected that the %systemd_post macro does enable the service. Need to verify this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but you need also the timer installed and enabled so katello-tracer-upload.{service,timer} would be the shortest option. The macros install the unit with the preset, so enabled/disabled depends on this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, only the timer need to activated. I adapted the spec file accordingly. but actually, I can only fully test it if Katello/katello-host-tools#171 is merged.
See https://documentation.suse.com/en-us/sle-micro/6.0/html/Micro-systemd-working-with-timers/index.html and


# replace @SBIN_PATH@ in the service file with the actual path to the executable
sed -i "s|@SBIN_PATH@|%{_sbindir}|" %{buildroot}%{_unitdir}/katello-tracer-upload.service
%endif

%clean
Expand All @@ -223,6 +233,25 @@ katello-enabled-repos-upload 2> /dev/null
exit 0
%endif

%if %{build_tracer}
%post tracer
%pkg_systemd_post katello-tracer-upload.timer

if [ "$1" -eq 1 ]; then
systemctl enable --now katello-tracer-upload.timer >/dev/null 2>&1 || :
fi

%preun tracer
%pkg_systemd_preun katello-tracer-upload.timer

if [ "$1" -eq 0 ]; then
systemctl disable --now katello-tracer-upload.timer >/dev/null 2>&1 || :
fi
Comment on lines +244 to +249

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%systemd_preun already expands to systemctl disable --now when $1 == 0 (via systemd-update-helper remove-system-units). The manual call duplicates the same operation. Safe to remove the if block:

%preun tracer
%pkg_systemd_preun katello-tracer-upload.timer


%postun tracer
%pkg_systemd_postun katello-tracer-upload.timer
Comment on lines +251 to +252

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fedora convention is to pass both units so both get proper lifecycle handling:

%post tracer
%pkg_systemd_post katello-tracer-upload.service katello-tracer-upload.timer

%preun tracer
%pkg_systemd_preun katello-tracer-upload.service katello-tracer-upload.timer

%postun tracer
%pkg_systemd_postun katello-tracer-upload.service katello-tracer-upload.timer

For reference, logrotate does: %systemd_post logrotate.{service,timer}
https://src.fedoraproject.org/rpms/logrotate/blob/rawhide/f/logrotate.spec#_91

%endif
Comment on lines +251 to +253

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the above postun macro

Suggested change
%postun tracer
%pkg_systemd_postun katello-tracer-upload.timer
%endif
%postun tracer
%pkg_systemd_postun_with_restart katello-tracer-upload.timer
%pkg_systemd_postun katello-tracer-upload.service
%endif

SUSE %service_del_postun may already do restart (their macros may behave differently from Fedora). If so, the SUSE wrapper for _with_restart mapping to plain %service_del_postun is correct. But needs someone with SUSE access to verify.


%files
%defattr(-,root,root,-)
%if 0%{?rhel} == 6
Expand Down Expand Up @@ -273,7 +302,6 @@ exit 0
%dir %{_usr}/lib/zypp
%dir %{_usr}/lib/zypp/plugins
%dir %{plugins_dir}
%dir %{_sysconfdir}/cron.d/
%{plugins_dir}/tracer_upload.py
%else
%if %{yum_install}
Expand All @@ -284,12 +312,17 @@ exit 0
%endif
%{katello_libdir}/tracer
%{plugins_confdir}/tracer_upload.conf
%config(noreplace) %attr(0644, root, root) %{_sysconfdir}/cron.d/katello-tracer-upload
%{_unitdir}/katello-tracer-upload.service
%{_unitdir}/katello-tracer-upload.timer
%attr(750, root, root) %{_sbindir}/katello-tracer-upload
%endif


%changelog
* Tue Jun 09 2026 Bernhard Suttner <suttner@atix.de> - 4.6.0-1
- Use systemd timer implementation instead of cron based
solution for tracer upload

* Wed Nov 05 2025 Bernhard Suttner <suttner@atix.de> - 4.5.0-2
- Fix missing /etc/cron.d/ dir for SLES / OBS build.

Expand Down