Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 :

/var/log/mydomain.org/access.log
{
  weekly
  missingok
  rotate 52
  compress
  delaycompress
  notifempty
  create 640 root adm
  sharedscripts
  prerotate
      /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mydomain.org &> /dev/null
  endscript
  postrotate
      if [ -f /var/run/apache2.pid ]; then
          /etc/init.d/apache2 restart > /dev/null
      fi
  endscript
}

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
3  
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

2 Answers 2

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

...
postrotate
/etc/init.d/apache2 restart > /tmp/apache_restart.txt
endscript
}

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

 
discard

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.