Cent OS logrotate is not rotating httpd log

bisb asked:

My /etc/logrotate.d/httpd file content is

/var/log/httpd/access.log  {
maxage 90
/usr/bin/killall -HUP httpd
      ls -ltr /var/log/httpd/ | mail -s "$HOSTNAME: Apache restarted and log files rotated" info@email.com

while my /etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones

# use date as a suffix of the rotated file

# uncomment this if you want your log files compressed

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    create 0664 root utmp
    minsize 1M
    rotate 1

/var/log/btmp {
    create 0600 root utmp
    rotate 1

But at the weekend when the log is expected to be rotated, it is not. The new empty file is created but remains empty, while the last rotated file keeps on growing.
Then after i have to restart httpd service to start logging again.

What is the issue?

My answer:

Your logs were not rotated because they did not reach 50 MB in size yet.

Because you specified a size, the normal date-based log rotation does not take effect. Instead, the log is rotated when it exceeds the specified size, even if that time takes longer than a week or a month or whatever time period was otherwise specified.

As seen in the manual page:

size size
        Log files are rotated only if they grow bigger than size bytes.

If you want to rotate the log every week, but you want to rotate it sooner if it exceeds 50 MB, then use maxsize 50M.

maxsize size
        Log files are rotated when they grow bigger than size bytes even before
        the additionally specified time interval (daily, weekly, monthly, or
        yearly). The related size option is similar except that it is mutually
        exclusive with the time interval options, and it causes log files to be
        rotated without regard for the last rotation time. When maxsize is used,
        both the size and timestamp of a log file are considered.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.