[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: migration from cron.daily to systemd timers



Am 09.01.20 um 13:08 schrieb Michael Stone:
> On Wed, Jan 08, 2020 at 07:12:17PM -0800, Russ Allbery wrote:
>> Michael Stone <mstone@debian.org> writes:
>>> On Thu, Jan 09, 2020 at 02:09:12AM +0000, Paul Wise wrote:
>>
>>>> This is the main reason I haven't switched to systemd timers for my
>>>> personal crontab, I have some jobs that generate output (diffs of
>>>> various things mostly) but don't fail. There doesn't appear to be any
>>>> tool to monitor a tool and send a mail if it generates output or fails,
>>>> in the way that cron does.
>>
>>> mail -E ?
>>
>> Specifically:
>>
>>    ExecStart=/bin/sh -c '/path/to/job | /usr/bin/mail -E'
>>
>> in the service unit triggered by the timer unit should work, I think.
>> (I've not tested it.)
> 
> May need something like
> (job || echo Job failed) 2>&1 | mail -E
> or even
> 
> (job 2>&1 || echo Job failed) | tee /dev/stderr | mail -E
> 
> depending on the specific requirements, but in general this should be
> pretty straightforward


You might want to use  OnFailure=

https://www.freedesktop.org/software/systemd/man/systemd.unit.html#OnFailure=

https://serverfault.com/questions/694818/get-notification-when-systemd-monitored-service-enters-failed-state

You can set the OnFailure= action via a drop-in for individual services
without having to touch the original .service file.


With v244 it's also possible to set this OnFailure= action globally for
all services. The relevant part from the NEWS file:

>         * Unit files now support top level dropin directories of the form
>           <unit_type>.d/ (e.g. service.d/) that may be used to add configuration
>           that affects all corresponding unit files.


Or you use something like
https://github.com/joonty/systemd_mon



HTH,
Michael

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: