3 ms·
I suppose it would be quite nice to have a MailTo= directive in a service. When the service stops, systemd could retrieve whatever it logged to the journal and
by yrro 7y ago
I suppose it would be quite nice to have a MailTo= directive in a service. When the service stops, systemd could retrieve whatever it logged to the journal and mail it to the specified address.
Until such a feature is implemented, you could try:
ExecStart=/bin/bash -c 'shopt -o pipefail; mycommand | mail -s foo@example.com'
Certainly not as convenient as MailTo=, but a lot less complicated than using OnFailure= with a separate service that tries to mail you the output.
- alxlaz 7y agoHuh. I never thought of that, although it was so damn obvious (I feel twice as stupid now that I realize I do a version of that on my machine, albeit not in order to send mail). I guess that's what I get for going all "Arch Wiki will you please just show me how you kids are doing it today and leave me be" on it. But to be honest, not having to do <shell> -c <exec this or send me an email> ever again is one of the reasons why we're doing the whole systemd thing, and one of its big promises. If it comes to writing shell mantras again, I might as well use vixie cron (or one of its descendants) and benefit from 30+ years of bugfixes across more Unices than I can name, plus the acquired wisdom of the Interwebs. Edit: plus... does this still allow you to get the other goodies, like being able to specify environment variables for a specific job?
- yrro 7y agoNot sure I follow about the environment variables. As for 'exec this or send me an email' -- I would also much prefer to see this be done by systemd itself. Fortunately bash's 'pipefail' feature plus bsd-mailx's '-s' flag make this reasonably quick and sane; I wouldn't even bother to attempt it if I were stuck with POSIX sh or if the mail command lacked the logic to not send the mail if stdin is empty.
- alxlaz 7y ago> Not sure I follow about the environment variables. I thought that environment variable passed via the Environment= options might not be correctly set, but it seems they are :-).