3

Why are we setting daily/weekly/monthly option in config file, if we can do it in cron (and actually do)? What is the sense of this option ?

For example: I set to execute "logrotate -f /etc/logrotate.d/app" every day(daily). But in config file (/etc/logrotate.d/app) I'll set weekly:

/home/dirnov/www/letsee/logs/*.log {
        monthly
        missingok
        rotate 4
        compress
        notifempty
}

And I see that there is no sense of "monthly", because cron will do it "daily".

ilya_direct
  • 501
  • 1
  • 6
  • 13
  • The entry in the /etc/logrotate.d files specifies the rotation period for that specific file. The entry running logrotate from cron on a daily basis allows the logrotate program to read those configuration files in the logrotate.d directory and decide what is the appropriate action to take for each of the files (which probably have differing period specifications). – Shadowfen Apr 29 '17 at 02:34
  • `-f` will force the logs to rotate regardless of the rotation criteria. Doing a `-f` effectively removes a big part of the module. Here's some helpful information about same topic. http://stackoverflow.com/questions/2117771/is-it-possible-to-run-one-logrotate-check-manually – Mike D May 03 '17 at 23:27

1 Answers1

5

The relationship between crond and logrotate is fairly simple: cron runs logrotate once a day (see /etc/cron.daily/logrotate), and logrotate then decides what to do based on the configuration files. Your specific question regarding monthly is clarified in the logrotate(8) manpage:

monthly
Log files are rotated the first time logrotate is run in a month (this is normally on the first day of the month).

The effect of your config is that logfiles will grow over a month, and once a new month is started, logrotate will rename and then compress any non-zero-sized files that match the filespec you supplied.

Finally, if you use logrotate -f, logrotate will rotate the logs, regardless of the period set in the configuration. If you aren't using a distro-supplied cronjob, then remember not to supply -f.

(Note this answer assumes Debian and Ubuntu, as that's what I'm able to test easily on, but should apply more generally).

kiko
  • 180
  • 1
  • 8