1

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.

3
  • 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, 2013 at 20:13
  • Does it keep logging into the old file indefinitily? Sep 16, 2013 at 20:56
  • Can you please provide the output of logrotate --debug /etc/logrotate.d/YOURFILE? Sep 16, 2013 at 23:31

2 Answers 2

1

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

-1

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.

1
  • 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. Sep 16, 2013 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .