Created
March 15, 2024 06:39
-
-
Save digitalsignalperson/d1db4b41b369fdf74139d4eaa7f5fa34 to your computer and use it in GitHub Desktop.
template for a systemd service that logs a failed invocation to /home/asdf/alerts/%N-failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=my service | |
[Service] | |
Restart=always | |
RestartSec=10 | |
ExecStart= | |
Environment="ALERT_PATH=/home/asdf/%N-failure" | |
ExecStopPost=/bin/bash -c '\ | |
echo $$SERVICE_RESULT, $$EXIT_CODE, $$EXIT_STATUS | logger; \ | |
if [ "$$SERVICE_RESULT" != "success" ]; then \ | |
sudo -u asdf touch "$$ALERT_PATH"; \ | |
journalctl -u %n _SYSTEMD_INVOCATION_ID=$$INVOCATION_ID > "$$ALERT_PATH"; \ | |
fi \ | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment