Skip to main content

Logrotate

Main configuration

Although running the command "logrotate somefile" runs that file, it does NOT mean it will continue to run it at the intervals you want.

Logrotate works via cron, and by default it includes all configuration files in the /etc/logrotate.d/ directory. You need to copy whichever configuration file you want it to run into that directory.

Configuration directives

The "size" and "minsize" directives override others. If you set "size 1M" and "weekly", the weekly directive will be ignored - unless the file exceeds 1MB it won't be rotated no matter what.

The "maxsize" directive doesn't have this property - you can set this with the time-based directives to have a system of "rotate if too old OR too big".

Rotation behaviour

The default behaviour is to literally move the old log file and create a new one. This messes with Apache, which does not realise the log file has changed and will be delivering logs to an invalid file handle.

Use the "copytruncate" directive in your configuration file so that logrotate copies the contents of the log and then truncates the existing file, instead of moving the file. This way Apache continues logging as normal.