My current logrotate configuration looks like this (using logrotate 3.8.7)
"/var/log/haproxy.log" {
daily
size 250M
rotate 1
create 644 root root
missingok
compress
notifempty
copytruncate
}
It successfully runs once a day, but when size exceeds 250M it doesn't get rotated. So it waits until the end of the day to rotate, regardless of size.
I've read that there is the maxsize option, and after changing size 250M
to maxsize 250M
it still doesn't work.
Do I need to set a cron to run logrotate in an hourly manner, or logrotate gets run automatically because is listening to that file size, and I have something else wrong going on?
Best Answer
Yes, you need to run
logrotate
more than once a day to achieve this. This is answered in the seconds paragraph of the man pagelogrotate
(8):If you would like to run
logrotate
hourly instead of daily, you can move it:Since 3.8.1 there has been
maxsize
. The difference betweensize
andmaxsize
is described here:This would make both suitable for your use:
size
without any interval andmaxsize
if also interval is needed. However, this doesn't change the fact that by defaultlogrotate
runs only daily. That interval is suitable for most, as in most cases it takes a lot longer than a day for a log to grow over250M
.