Skip to content

Use systemd service and timer to upload katello tracer - #13505

Open
sbernhard wants to merge 1 commit into
theforeman:rpm/developfrom
ATIX-AG:use_systemd_timer_for_upload
Open

Use systemd service and timer to upload katello tracer#13505
sbernhard wants to merge 1 commit into
theforeman:rpm/developfrom
ATIX-AG:use_systemd_timer_for_upload

Conversation

@sbernhard

Copy link
Copy Markdown

Instead of using cron, use systemd service and timer to upload the katello tracer. This is modern solution which is also supported by SUSE Micro distribution (which does not deliver a cron daemon)

@sbernhard
sbernhard requested a review from a team as a code owner May 21, 2026 14:10
@sbernhard
sbernhard marked this pull request as draft May 21, 2026 14:10
@sbernhard

Copy link
Copy Markdown
Author

Requires Katello/katello-host-tools#171 to be merged first.

@sbernhard
sbernhard force-pushed the use_systemd_timer_for_upload branch from 0bfb84a to 9863bd4 Compare May 21, 2026 15:11
Comment on lines -213 to +209
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

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

@ogajduse

Copy link
Copy Markdown
Member

[test rpm]

@ianballou

Copy link
Copy Markdown

katello-host-tools 4.6.0 is ready for packaging https://github.com/Katello/katello-host-tools/releases/tag/4.6.0

@sbernhard
sbernhard force-pushed the use_systemd_timer_for_upload branch from 24be2f6 to 5f17224 Compare June 9, 2026 16:34
@sbernhard
sbernhard marked this pull request as ready for review June 9, 2026 16:34
@sbernhard
sbernhard force-pushed the use_systemd_timer_for_upload branch 2 times, most recently from 1d65cf2 to 22c465c Compare June 9, 2026 21:58
@sbernhard

Copy link
Copy Markdown
Author

Packaging done @ianballou

@sbernhard
sbernhard force-pushed the use_systemd_timer_for_upload branch 2 times, most recently from cf19a84 to 39efcab Compare June 10, 2026 09:43
Instead of using cron, use systemd service and timer to upload the
katello tracer. This is modern solution which is also supported by
SUSE Micro distribution (which does not deliver a cron daemon)
@sbernhard
sbernhard force-pushed the use_systemd_timer_for_upload branch from 39efcab to 916b3a2 Compare June 10, 2026 10:01

@ogajduse ogajduse left a comment

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.

I checked how Fedora packages (logrotate, plocate, fstrim) handle systemd timers in their specs, and have a few notes.

Comment on lines +244 to +249
%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

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

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

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

Comment on lines +6 to +14
%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

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.

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants