Created
September 11, 2014 08:44
-
-
Save kylemanna/f060a189916b2f57c2d6 to your computer and use it in GitHub Desktop.
Example failure handler for systemd that emails me
This file contains 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
#!/bin/bash | |
# | |
# Author: Kyle Manna <kyle@kylemanna.com> | |
# | |
# Simple systemd script used to be called via something like: | |
# | |
# Example Unit section of a service file: | |
# | |
# [Unit] | |
# ... | |
# Onfailure=failure-email@%i.service | |
# | |
# | |
# failure-email@.service: | |
# | |
# [Unit] | |
# Description=OnFailure for %i | |
# | |
# [Service] | |
# Type=oneshot | |
# ExecStart=/path/to/onfailure.sh %i | |
# | |
svc=${1-unknown} | |
email=${2-kyle@kylemanna.com} | |
cat <<EOF | sendmail -i "$email" | |
Subject: [$HOSTNAME] OnFailure Email for $svc | |
# Status | |
$(systemctl --user status -l -n 1000 "$svc") | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment