Bug#929756: Appease systemd-cron by doing "if P;then C;fi" (not "P&&C") in crontab

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bug#929756: Appease systemd-cron by doing "if P;then C;fi" (not "P&&C") in crontab

Trent W. Buck
Package: ntpsec
Version: 1.1.3+dfsg1-2
Severity: wishlist
Tags: patch

When using systemd and systemd-cron (instead of ISC vixie cron),
your cron jobs are marked as "failing" by systemd, because
they have non-zero exit status.

This is because you do

    test1 && test2 && do something

So if test1 fails, it's a non-zero exit status, and it shows up in "systemctl --state=failed", and
"systemctl status" marks the whole system as "degraded".
Also systemd-crond sends an email about it, which vixie cron only does if there's stdout/stderr.

The fix is simple:

    - test1 && test2 && do something
    + if test1 && test2; then do something; fi

Here's the actual diff on my running system:

    diff --git a/cron.d/ntpsec b/cron.d/ntpsec
    index fb2a9b4..57054e1 100644
    --- a/cron.d/ntpsec
    +++ b/cron.d/ntpsec
    @@ -1 +1 @@
    -25 6     * * * root [ ! -d /run/systemd/system ] && [ -x /usr/lib/ntp/rotate-stats ] && /usr/lib/ntp/rotate-stats
    +25 6     * * * root if [ ! -d /run/systemd/system ] && [ -x /usr/lib/ntp/rotate-stats ]; then /usr/lib/ntp/rotate-stats; fi
    diff --git a/cron.d/ntpsec-ntpviz b/cron.d/ntpsec-ntpviz
    index d808c81..c217bcc 100644
    --- a/cron.d/ntpsec-ntpviz
    +++ b/cron.d/ntpsec-ntpviz
    @@ -1,4 +1,4 @@
     53 *     * * * root if [ ! -d /run/systemd/system ] ; then ntpviz -p 1 -d /var/log/ntpsec -o /var/lib/ntpsec/ntpviz/day  @/etc/ntpviz/options 2> /dev/null ; find /var/lib/ntpsec/ntpviz/day  -type f -mtime +1 -delete ; fi
     45 11,23 * * * root if [ ! -d /run/systemd/system ] ; then ntpviz -p 7 -d /var/log/ntpsec -o /var/lib/ntpsec/ntpviz/week @/etc/ntpviz/options 2> /dev/null ; find /var/lib/ntpsec/ntpviz/week -type f -mtime +7 -delete ; fi
    -*/5 *    * * * root [ ! -d /run/systemd/system ] && [ -e /run/gpsd.sock ] && [ -x /usr/sbin/ntploggps ] && /usr/sbin/ntploggps -o -l /var/log/ntpsec/gpsd 2> /dev/null
    -*/5 *    * * * root [ ! -d /run/systemd/system ] && [ -x /usr/sbin/ntplogtemp ] && /usr/sbin/ntplogtemp -o -l /var/log/ntpsec/temps
    +*/5 *    * * * root if [ ! -d /run/systemd/system ] && [ -e /run/gpsd.sock ] && [ -x /usr/sbin/ntploggps ]; then /usr/sbin/ntploggps -o -l /var/log/ntpsec/gpsd 2>/dev/null; fi
    +*/5 *    * * * root if [ ! -d /run/systemd/system ] && [ -x /usr/sbin/ntplogtemp ]; then /usr/sbin/ntplogtemp -o -l /var/log/ntpsec/temps; fi