2

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

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

while my /etc/logrotate.conf

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

# keep 4 weeks worth of backlogs
rotate 4

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

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# 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 {
    monthly
    create 0664 root utmp
    minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    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?

bishnub
  • 23
  • 2
  • 1
    Check your Apache logs if it received a SIGHUP on the weekend. I personally would use `/sbin/service httpd reload` instead of the `killall` but your version should work too. – faker Mar 30 '15 at 11:42

1 Answers1

2

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.
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972