Systemd OnFailure=: Limits on Silent Alerting for Service Failures in Arch Linux
0 reputation · 11 Dec 2020, 02:01 UTC
0 reputation · 11 Dec 2020, 02:01 UTC
We want to receive actionable alerts for service failures without desktop pop‑ups in Arch Linux.
Arch Linux lacks clear guidance on whether to use OnFailure= or pacman hook scripts for non‑noisy alerts.
To receive actionable alerts without desktop pop-ups, use the OnFailure= directive in your service unit to trigger a dedicated Type=oneshot service. This decoupled approach ensures that alerts are handled by system-level tools (like an MTA) rather than user-session notification daemons.
The OnFailure= directive is reliable for any unit that enters the failed state. This includes:
Assumption: This behavior assumes the service is managed by systemd. It will not trigger if a service is stopped manually via systemctl stop or if the process exits with code 0 despite a logical failure.
To send emails or logs without a desktop session, you must use a system-wide Mail Transfer Agent (MTA) such as msmtp or postfix. User-level mail configurations are not accessible to system units.
/etc/systemd/system/failure-alert.service
[Unit]
Description=Silent Failure Alert
[Service]
Type=oneshot
ExecStart=/usr/bin/mail -s "Service Failure: %n" [contact removed] < /dev/null
/etc/systemd/system/myapp.service)
[Unit]
Description=My Application
OnFailure=failure-alert.service
systemctl daemon-reload.For package installation failures, pacman hooks are the preferable approach. Systemd cannot natively monitor the internal state of a pacman transaction because these events occur outside the service lifecycle.
OnFailure= is ineffective for standard package updates unless the update process is wrapped in a custom systemd unit.To verify the setup, create a temporary service that executes /usr/bin/false and check the status of the alert unit:
systemctl list-units --state=failed
Confirm the alert was sent by checking the journal: journalctl -u failure-alert.service.
Note: Please specify if you are using a local MTA or a remote SMTP relay, as this changes the ExecStart configuration for the alert service.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.