Use systemd service and timer to upload katello tracer - #13505
Conversation
|
Requires Katello/katello-host-tools#171 to be merged first. |
0bfb84a to
9863bd4
Compare
| 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
[test rpm] |
a07295e to
24be2f6
Compare
|
katello-host-tools 4.6.0 is ready for packaging https://github.com/Katello/katello-host-tools/releases/tag/4.6.0 |
24be2f6 to
5f17224
Compare
1d65cf2 to
22c465c
Compare
|
Packaging done @ianballou |
cf19a84 to
39efcab
Compare
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)
39efcab to
916b3a2
Compare
ogajduse
left a comment
There was a problem hiding this comment.
I checked how Fedora packages (logrotate, plocate, fstrim) handle systemd timers in their specs, and have a few notes.
| %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 |
There was a problem hiding this comment.
%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 |
There was a problem hiding this comment.
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.timerFor reference, logrotate does: %systemd_post logrotate.{service,timer}
https://src.fedoraproject.org/rpms/logrotate/blob/rawhide/f/logrotate.spec#_91
| %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 |
There was a problem hiding this comment.
| %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.timerutil-linux / fstrim (src):
%postun
%systemd_postun_with_restart fstrim.timer
%systemd_postun fstrim.serviceNote 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.
| %postun tracer | ||
| %pkg_systemd_postun katello-tracer-upload.timer | ||
| %endif |
There was a problem hiding this comment.
Same as for the above postun macro
| %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.
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)