Skip to content

Instantly share code, notes, and snippets.

@pbelskiy
Created August 4, 2021 12:09
Show Gist options
  • Save pbelskiy/ea7e11b93ce817648b07e75848b7c1ea to your computer and use it in GitHub Desktop.
Save pbelskiy/ea7e11b93ce817648b07e75848b7c1ea to your computer and use it in GitHub Desktop.
systemd restart on failed and notify
[Unit]
After=postgresql.service
[Service]
Type=simple
ExecStartPre=/bin/bash -c '(journalctl -n 5 --user-unit=%n | grep "Failed with result") && \
(journalctl -n 50 --user-unit=%n | mailx -s "[systemd] %n failed" user@domain.ua) || \
true'
ExecStart=/usr/bin/python3 /home/user/daemon.py
Environment=PYTHONUNBUFFERED=1
Restart=on-failure
RestartSec=10s
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment