#940711 logrotate: with systemd, no mail in case of error

Package:
logrotate
Source:
logrotate
Description:
Log rotation utility
Submitter:
Vincent Lefevre
Date:
2019-09-22 15:09:06 UTC
Severity:
normal
#940711#5
Date:
2019-09-19 10:46:17 UTC
From:
To:
In case of an error during the log rotation, e.g. a gzip failure
with "warning: file timestamp out of range for gzip format"[*],
when log rotation is done via the systemd timer, one does not get
any mail, contrary to cron jobs.

The error message is in the systemd logs, but this is not sufficient.
Logs are fine for informational messages in order to debug or to try
to find the cause of a problem, but for something that requires a
manual intervention like here, the user must be informed, otherwise
the problem may remain unnoticed for a long time.

[*] See e.g. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504333
    but note that the original problem with missing mail in this old
    bug was different as systemd did not exist at that time.

#940711#10
Date:
2019-09-20 18:05:53 UTC
From:
To:
This is indeed a disadvantage of systemd-timers compared to cron jobs.
(see https://wiki.archlinux.org/index.php/Systemd/Timers#Caveats)

In my opinion the advantages (more robust triggering on non 24/7 systems,
more security by service hardening options) outweigh.

It is possible to switch back by disabling the timer

    systemctl stop logrotate.timer
    systemctl disable logrotate.timer

and commenting out the following lines in /etc/cron.daily/logrotate

    if [ -d /run/systemd/system ]; then
        exit 0
    fi

You can monitor 'systemctl is-system-running', or use something like
the following timer:

#### timer
[Unit]
Description=Daily log warnings report
After=systemd-journald.service
[Timer]
OnCalendar=*-*-* 23:59:40
AccuracySec=10s
Persistent=true
[Install]
WantedBy=systemd-journald.service

#### service
[Unit]
Description=Daily log warnings report
[Service]
Type=oneshot
ExecStart=/bin/sh -c "/bin/journalctl --priority error --since today |
mail -s 'log warnings daily report' root"
KillMode=process

#940711#15
Date:
2019-09-21 00:53:25 UTC
From:
To:
For non 24/7 systems, there is anacron.

There is no "error" priority. Perhaps you meant "err", but that's
useless since it is too low: there are many non-fatal errors in the
logs. The "crit" priority gives only interesting errors, i.e. those
that may affect the system (and security alerts); for instance,
exim does that when /var/log/exim4/paniclog has non-zero size
(this happened when it could not bind to port 25). I think that
logrotate should use that when it cannot rotate a log file.

#940711#20
Date:
2019-09-22 14:52:01 UTC
From:
To:
Perhaps something like that should be implemented in standard:

https://wiki.archlinux.org/index.php/Systemd/Timers#MAILTO