Last Updated: February 25, 2016
·
985
· geetotes

How to fail at logrotate

If you're like me, you've named your httpd log files all types of crazy things. Like mysite.com.access and mysite.com.error. And, if you're also like me, you have a nice little entry in /etc/logrotate.d to clean stuff up.

/var/log/httpd/* {
  weekly
  rotate 5
  postrotate
    /usr/sbin/apachectl -k graceful
  endscript
}

Of course, this entry is wrong wrong wrong!. First off, you're going to end up having O^n logs, since every roatation will end up with a mysite.com.access.1 created, then that mysite.com.access.1 will be rotated again and a mysite.com.access.1.1 will be created.

On top of that, there is no sharedscripts directive, so the postrotate command will be run after every successful log rotation. Soon enough, you're rebooting apache O^n times every week on Sunday!

Here's how to not rotate those pesky *.1 files and use the sharedscripts directive so the postrotate command will only be run once logrotate is finished with the directive.

/var/log/httpd/*[!0-9] {
  sharedscripts
  weekly
  rotate 5
  postrotate
    /usr/sbin/apachectl -k graceful
  endscript
}

Stay tuned for my next book, How to Cause Bizzare Problems with Poorly Configured Services -- For Hackers!