Skip to content

Instantly share code, notes, and snippets.

@digitalsignalperson
Created March 15, 2024 06:39
Show Gist options
  • Save digitalsignalperson/d1db4b41b369fdf74139d4eaa7f5fa34 to your computer and use it in GitHub Desktop.
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
[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