Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Fri Nov 13, 2009 8:04 am 
Offline
Senior Newbie

Joined: Fri Sep 14, 2007 1:40 pm
Posts: 17
Hi all,

I'm having a hard time to figure this out. :(

I have 3 apache virtual hosts running on my Linode VPS. I want to rotate them every week (similar to what happens to original apache logs).

I went to /etc/logrotate.d/apache2 (the original file) and edited it:

Code:
/var/log/apache2/*.log {
   olddir /var/log/oldlogs/apache2
   weekly
   missingok
   rotate 8
   compress
   delaycompress
   notifempty
   create 640 root adm
   sharedscripts
   postrotate
      if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
         /etc/init.d/apache2 reload > /dev/null
      fi
   endscript
}

# virtual hosts
/home/ngm/www/*/log/*.log {
   olddir old
   weekly
   missingok
   rotate 5200
   compress
   delaycompress
   notifempty
   create 644 root root
   sharedscripts
   postrotate
      if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
         /etc/init.d/apache2 reload > /dev/null
      fi
   endscript
}


This first configuration is the original one, it's working ok. I wrote the second (virtual hosts) for my vhosts based on the first one.

My vhosts logs are rotating fine but apache keeps writing on the old files.

Any suggestion?

Thank you so much.


Top
   
 Post subject:
PostPosted: Fri Nov 13, 2009 8:24 am 
Offline
Newbie
User avatar

Joined: Fri Nov 13, 2009 8:14 am
Posts: 3
Website: http://mattgemmell.com/
Location: Edinburgh, Scotland (UK)
I post this as a total logrotate noob who just coincidentally happened to configure my own vhosts logrotate block yesterday. A few points to consider:

1. Does the "old" dir in each vhost's "logs" dir already exist? You might have to create it first.

2. A weekly logrotate probably won't run until the second week; the first time it seems to just note that it's looked at that dir, then the next time it runs it'll actually do the rotation.

3. You might want to specify the error.log and access.log files separately in your logrotate block:

/home/ngm/www/*/log/access.log /home/ngm/www/*/log/error.log {

Otherwise, I think logrotate might treat them all as one batch, whereas you probably want it to keep so many old access logs, _and_ so many old error logs.

4. Did you really mean "rotate 5200"? My understanding was that this means to keep 5,200 logs in total (5,199 old logs, plus the current one). That seems like a lot. For a weekly log, that's a century worth!

My vhost config (it's a daily rather than weekly) is pretty much identical to yours, except I don't use an olddir and I keep just 7 logs of each type in total. It seems to work fine, judging by the files and their modification dates.

You can do logrotate -d path/to/conf/file to make logrotate run in debug mode, which doesn't actually do any rotation or change its internal state, but spits out some diagnostic info.

_________________
Matt Legend Gemmell
Mac OS X / iPhone Developer
Blog: http://mattgemmell.com/
Work: http://instinctivecode.com/


Top
   
 Post subject:
PostPosted: Fri Nov 13, 2009 2:13 pm 
Offline
Senior Newbie

Joined: Fri Sep 14, 2007 1:40 pm
Posts: 17
I Matt, thank you for your answer.

Bellow I add some notes:

Matt Gemmell wrote:
I post this as a total logrotate noob who just coincidentally happened to configure my own vhosts logrotate block yesterday. A few points to consider:

1. Does the "old" dir in each vhost's "logs" dir already exist? You might have to create it first.


Yes, it's true. And I took care of it. Logs are rotating correctly (moving to old log, and creating new log file).

Quote:
2. A weekly logrotate probably won't run until the second week; the first time it seems to just note that it's looked at that dir, then the next time it runs it'll actually do the rotation.


Also true, but I set up my system 3 weeks ago. Two rotations already took place. Files are rotated, Apache2 keeps writing in the old ones: access.log.1 and error.log.1

Quote:
3. You might want to specify the error.log and access.log files separately in your logrotate block:
/home/ngm/www/*/log/access.log /home/ngm/www/*/log/error.log {

Otherwise, I think logrotate might treat them all as one batch, whereas you probably want it to keep so many old access logs, _and_ so many old error logs.


No, it treats files separatelly. For instance, the apache2 log configuration: /var/log/apache2/*.log { it rotates two files for two files with just one path.

Quote:
4. Did you really mean "rotate 5200"? My understanding was that this means to keep 5,200 logs in total (5,199 old logs, plus the current one). That seems like a lot. For a weekly log, that's a century worth!


Yes, I really meant 5200... it's about 100 years of logs. I wasn't using any analytics software so I wanted to keep all records for futures statistics (num visitors,...) processing. Now I'm using Google Analytics so I'll give up on that.

Quote:
My vhost config (it's a daily rather than weekly) is pretty much identical to yours, except I don't use an olddir and I keep just 7 logs of each type in total. It seems to work fine, judging by the files and their modification dates.

You can do logrotate -d path/to/conf/file to make logrotate run in debug mode, which doesn't actually do any rotation or change its internal state, but spits out some diagnostic info.


As I stated, my problem is not in rotation but afterwards. Apache2 keeps writing to the old files. I fix the problem by restarting Apache2 manually.

I don't know what can be wrong.


Top
   
 Post subject:
PostPosted: Sat Nov 14, 2009 2:08 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
Look into the postrotate script:
Code:
      if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
         /etc/init.d/apache2 reload > /dev/null
      fi

If the command /etc/init.d/apache2 reload works fine by itself, then there's probably some problem with Apache not writing a pid file or writing it someplace it's not expected.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group