Bug 2371317 - Use `systemctl try-reload-or-restart` in logrotate postrotate script
Summary: Use `systemctl try-reload-or-restart` in logrotate postrotate script
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: svxlink
Version: 42
Hardware: Unspecified
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Scott K Logan
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-06-09 22:48 UTC by Marcos Mello
Modified: 2025-06-11 19:03 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Marcos Mello 2025-06-09 22:48:43 UTC
Use `systemctl try-reload-or-restart` in logrotate postrotate script

`systemctl try-reload-or-restart` 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`. The action of remotetrx.service's `ExecReload=` sends the same signal as currently sent by `killall`, making it a suitable replacement. This ensures precise signal sending to the intended process, reducing the risk of errors in process identification. Additionally, `systemctl try-reload-or-restart` is silent by default and returns zero if the daemon is inactive. It also logs the action in the service's journal, providing a record of actions taken.

The logrotate configuration snippet:

# cat /etc/logrotate.d/remotetrx
/var/log/remotetrx {
    missingok
    notifempty
    weekly
    create 0644 svxlink daemon
    postrotate
        killall -HUP remotetrx
    endscript
}

In the postrotate script, killall can be replaced by:

/usr/bin/systemctl try-reload-or-restart remotetrx.service

Because:

# systemctl show -P ExecReload remotetrx.service
{ path=/bin/kill ; argv[]=/bin/kill -s HUP $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
# systemctl show -P MainPID remotetrx.service
1748
# pgrep remotetrx
1748

Reproducible: Always




Additional Information:
svxlink-server-1.8.0-5.fc42.x86_64

Comment 1 Marcos Mello 2025-06-11 19:03:52 UTC
The same applies to svxlink:

# cat /etc/logrotate.d/svxlink-server
/var/log/svxlink {
    missingok
    notifempty
    weekly
    create 0644 svxlink daemon
    postrotate
        killall -HUP svxlink
    endscript
}

In the postrotate script, killall can be replaced by:

/usr/bin/systemctl try-reload-or-restart svxlink.service

Because:

# systemctl show -P ExecReload svxlink.service
{ path=/bin/kill ; argv[]=/bin/kill -s HUP $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
# systemctl show -P MainPID svxlink.service
3418
# pgrep svxlink
3418


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