Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I usually create my access and error logs in a domain-name folder under /var/log, and these files are rotated with logrotate using this conf :

  rotate 52
  create 640 root adm
      /usr/local/awstats/wwwroot/cgi-bin/ -update &> /dev/null
      if [ -f /var/run/ ]; then
          /etc/init.d/apache2 restart > /dev/null

I have regularly this problem : my access.log is rotated to access.log.1, but apache2 keeps on logging access on access.log.1.

I can't figure out why this is happening. Any help ?

Thanks in advance.

share|improve this question
Double check that the postrotate part gets correctly executed (don't redirect to /dev/null but to some file you can check!). – faker Sep 16 '13 at 20:13
Does it keep logging into the old file indefinitily? – Christopher Perrin Sep 16 '13 at 20:56
Can you please provide the output of logrotate --debug /etc/logrotate.d/YOURFILE? – Stefan Lasiewski Sep 16 '13 at 23:31

I'm going to guess that you're apache process is not putting a pid file in "/var/run/" and therefore your postrotate never executes. While troubleshooting (as faker's comment suggests) maybe try this:

/etc/init.d/apache2 restart > /tmp/apache_restart.txt

Then tomorrow look at /tmp/apache_restart.txt with more /tmp/apache_restart.txt

share|improve this answer

Why would you use logrotate to rotate apache logs, when you could have it all on one simple directive?

You could use something like something like:

ErrorLog "|/usr/sbin/rotatelogs /var/logs/httpd/error_log 86400"

This way you wont't need to handle the locks on the files, and apache would rotate the logs for you.

share|improve this answer
LogRotate is a perfectly valid way to handle Apache log rotation, and is in line with how many other Linux software do log rotation. To improve your answer, please reword your answer to be friendlier and provide reasons why jpicaude should your solution instead of what he has already. – Stefan Lasiewski Sep 16 '13 at 23:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.