[systemd-devel] Restart and RestartSec in packaged .service files
Reindl Harald
h.reindl at thelounge.net
Tue Sep 20 03:30:23 PDT 2011
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 at .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 at 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 at rh:~]$ cat /lib/systemd/system/send-mail-on-failure at .service
[Unit]
Description=Send mail on failure of %I
[Service]
ExecStart=/scripts/send-mail-on-failure.sh %I
[root at rh:~]$ cat /scripts/send-mail-on-failure.sh
#!/bin/bash
logger "SYSTEMD FAILURE $1"
[root at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20110920/554e2604/attachment.pgp>
More information about the systemd-devel
mailing list