Am 01.09.2011 16:25, schrieb Lennart Poettering:
> if i say "Restart=always" i want a mail if this happens
> not a own unit-file
write a unit file that sends a mail, something like this: 

send-mail-on-failure@.service:
<snip>
[Unit]
Description=Send mail on failure of %I

[Service]
ExecStart=/path/to/my/script.sh %I
</snip>

/path/to/my/script.sh:
<snip>
#!/bin/sh

(
echo "$1 crashed, do something, sir!"
echo "here's the systemctl status output:"
systemctl status "$1"
) | mail lennart -s "OMG! PONIES!"
</snip>

And then add OnFailure=send-mail-on-failure@%P to your units where you
want a mail to be sent
________________________

this seems not to work because after "systemctl --system daemon-reload" the
first error hits /var/log/messages and again the question why not
simplify this with "OnFailure=send-mail" instead writing scripts
and "services" to send a simple mail - this is the exact opposite
of simplify what systemd should do like Lennart always says

[root@rh:~]$ cat messages 
Sep 20 12:24:36 rh systemd[1]: Reloading.
Sep 20 12:24:36 rh systemd[1]: Failed to add dependency on 
send-mail-on-failure@%P, ignoring: Invalid argument

[root@rh:~]$ cat /lib/systemd/system/send-mail-on-failure@.service 
[Unit]
Description=Send mail on failure of %I
[Service]
ExecStart=/scripts/send-mail-on-failure.sh %I

[root@rh:~]$ cat /scripts/send-mail-on-failure.sh
#!/bin/bash
logger "SYSTEMD FAILURE $1"

[root@rh:~]$ cat /lib/systemd/system/httpd.service 
[Unit]
Description=HTTP Server (prefork MPM)
After=syslog.target local-fs.target network.target mysqld.service
OnFailure=send-mail-on-failure@%P






Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to