Bug 2372534 - Use `systemctl kill` in logrotate postrotate script
Summary: Use `systemctl kill` in logrotate postrotate script
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: ntpsec
Version: 42
Hardware: Unspecified
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Miroslav Lichvar
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-06-12 18:24 UTC by Marcos Mello
Modified: 2025-06-16 07:48 UTC (History)
3 users (show)

Fixed In Version: ntpsec-1.2.4-3.fc43
Clone Of:
Environment:
Last Closed: 2025-06-16 07:48:49 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Marcos Mello 2025-06-12 18:24:30 UTC
`systemctl kill` leverages systemd's knowledge of the daemon's main PID, eliminating the need to rely on PID files or external tools like `killall` or `pkill`. This ensures precise signal sending to the intended process, reducing the risk of errors in process identification. Additionally, using `systemctl kill` logs the signal sending in the service's journal, providing a record of actions taken. Requires selinux-policy-41.43 or higher (see https://bugzilla.redhat.com/show_bug.cgi?id=2369644), available as an update for F41, F42, and Rawhide.

https://bodhi.fedoraproject.org/updates/FEDORA-2025-eb98eb9e24 (F41 -- will go to stable in a few days)
https://bodhi.fedoraproject.org/updates/FEDORA-2025-f9f097f491 (F42 -- stable)
https://bodhi.fedoraproject.org/updates/FEDORA-2025-3db4c0ec1c (Rawhide)

The logrotate configuration snippet:

# cat /etc/logrotate.d/ntpsec.conf
# On Linux systems with logrotate,
#  drop this into /etc/logrotate.d/ntpd
# That will rotate ntpd.log monthly and then
# kick ntpd to switch to the new log file.

/var/log/ntpd.log {
    monthly
    missingok
    postrotate
      /usr/bin/killall -HUP ntpd
    endscript
    rotate 6
}

In the postrotate script, killall can be replaced by:

/usr/bin/systemctl kill --signal=HUP --kill-whom=main ntpd.service 2>/dev/null || true

Because:

# systemctl show -P MainPID ntpd.service
2411
# pgrep ntpd
2411

Reproducible: Always




Additional Information:
ntpsec-1.2.4-1.fc42.x86_64

Comment 1 Miroslav Lichvar 2025-06-16 07:48:49 UTC
Applied to the rawhide brach. Thanks!


Note You need to log in before you can comment on or make changes to this bug.