Skip to content

Instantly share code, notes, and snippets.

@mydreambei-ai
Created March 3, 2017 08:20
Show Gist options
  • Save mydreambei-ai/8f72b6e982b4d81362eacc822f346369 to your computer and use it in GitHub Desktop.
Save mydreambei-ai/8f72b6e982b4d81362eacc822f346369 to your computer and use it in GitHub Desktop.
systemd OnFailure send mail
#http://unix.stackexchange.com/questions/314329/mailx-not-sending-email-when-run-as-a-systemd-service
systemd send mail is odd, using mail must set flag -vv
# shadowsocks.service
[Unit]
Description=The Postgresql Server Restful API
OnFailure=failure-email@%n.service
[Service]
Type=simple
ExecStart=/usr/bin/sslocal -c /etc/shadowsocks.json
ExecStop=/bin/kill ${MAINPID}
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
#[email protected]
[Unit]
Description=OnFailure for %n
[Service]
Type=oneshot
ExecStart=/home/lmy/onfailure.sh %N
#onfailure.sh
#!/bin/sh
echo $1 | /usr/bin/mail -vv -s "monit" [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment