Linux – Why does the CentOS logrotate run at random times

centoscronlinuxlogrotate

I put a logrotate configuration file in /etc/logrotate.d/ and expected the logs to rotate at a consistent time; however, they do not… log rotation times are seemingly random +/- one hour.

Why are the log rotation start times random, and how can I change this?


Informational: my logrotate config file looks like this…

/opt/backups/network/*.conf {
        copytruncate
        rotate 30
        daily
        create 644 root root
        dateext
        maxage 30
        missingok
        notifempty
        compress
        delaycompress
        postrotate
            ## Create symbolic links in daily/
            PATH=`/usr/bin/dirname $1`;
            FILE=`/bin/basename $1`;
            /bin/ln -s $1 $PATH/daily/$FILE
        endscript
}

Best Answer

The key is knowing that CentOS runs the scripts in /etc/cron.{daily,weekly,monthly} from anacron... /etc/anacrontab is setting RANDOM_DELAY, which does what you might expect (it delays up to RANDOM_DELAY minutes before starting the job)...

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days   delay in minutes   job-identifier   command
1       5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

Setting RANDOM_DELAY=0 / START_HOURS_RANGE=3 fixed the problem...

EDIT

After further thought, I am going to remove anacron and install normal vixie cron...