Logrotate: Differences between UCS 4.x and UCS 5.x

UCS uses logrotate to rotate the log files (see UCS manual, ucr search logrotate and man logrotate for details).

UCS 4.x

  • In UCS 4.4, logrotate is invoked via a daily cronjob:
$ ls -l /etc/cron.daily/
[...]
-rwxr-xr-x 1 root root  377 Aug 29  2018 logrotate
[...]
  • cron.daily runs by default at 06:25 in the morning:
$ cat /etc/crontab
[...]
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
[...]
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
[...]

UCS 5.x

  • In UCS 5.0, we still have a daily cronjob for logrotate, but this is only a fallback:
$ cat /etc/cron.daily/logrotate
#!/bin/sh

# skip in favour of systemd timer
if [ -d /run/systemd/system ]; then
    exit 0
fi
[...]
  • What takes priority, is a new systemd timer:
$ systemctl list-timers
NEXT                         LEFT       LAST                         PASSED       UNIT                         ACTIVATES
[...]
Thu 2021-12-16 00:00:00 CET  12h left   Wed 2021-12-15 00:00:01 CET  11h ago      logrotate.timer              logrotate.service
[...]
  • This still runs the same logrotate configuration, but the execution time has changed. By default, the systemd timer for logrotate now runs at midnight (00:00)!

How to change the logrotate systemd timer execution time

In some cases, 00:00 might be a really bad time to do logrotating, especially if the rotation also triggers restarts of services. In this case, we can modify the execution time of the logrotate.timer:

  • We create a custom timer config via:
systemctl edit logrotate.timer
  • This will create a new file /etc/systemd/system/logrotate.timer.d/override.conf that allows us to overwrite the default execution time
  • After running systemctl edit logrotate.timer, add the following to the now open file:
[Timer]
OnCalendar=
OnCalendar=*-*-* 06:25:00
  • The first line clears the entry (daily) from the default config, the second line sets the new time
  • Then save and close the file
  • Verify with systemctl cat logrotate.timer:
$ systemctl cat logrotate.timer
# /lib/systemd/system/logrotate.timer
[Unit]
Description=Daily rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true

[Install]
WantedBy=timers.target

# /etc/systemd/system/logrotate.timer.d/override.conf
[Timer]
OnCalendar=
OnCalendar=*-*-* 06:25:00
  • Afterwards, a systemctl list-timers should show us the correct NEXT execution time:
 systemctl list-timers
NEXT                         LEFT         LAST                         PASSED       UNIT                         ACTIVATES
[...]
Thu 2021-12-16 06:25:00 CET  18h left     Wed 2021-12-15 12:05:26 CET  1min 28s ago logrotate.timer              logrotate.service
[...]
2 Likes

This topic was automatically closed after 24 hours. New replies are no longer allowed.

Mastodon