Skip to content

Instantly share code, notes, and snippets.

@kylemanna
Created September 11, 2014 08:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemanna/f060a189916b2f57c2d6 to your computer and use it in GitHub Desktop.
Save kylemanna/f060a189916b2f57c2d6 to your computer and use it in GitHub Desktop.
Example failure handler for systemd that emails me
#!/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