Linux Box Admin
Trusted Remote Administration
logo

Tilde
What's new
Articles
Micro HowTos
About
Contact







Logrotate
(0 votes)
Wednesday, 07 March 2007
   
    Logrotate    
     
       
 

Logrotate is program that manages and optionally compresses log files. The configuration determines how many files of each type are kept based on age and/or file size.

The global configuration file is /etc/logrotate.conf. Some distros also include program specific configuration files stored in /etc/logrotate.d/. Each type of log file can have different rotation schedules.

Global defaults

In most systems, the default configuration keeps 4 backup log files and rotates them weekly.

Sample apache logrotate configuration

/var/log/httpd/*log {
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null`
endscript
}

The path defines what log files are controlled by this entry.
missingok means to continue if no logs files are found.
notifempty means do not rotate the file if it is empty.
sharedscripts means run the prerotate and postrotate scripts once regardless of how many log files are rotated.
postrotate defines a command to run after log files have been rotated. In this case, it sends the hang up signal to apache to tell it to reread its configuration file.

Custom apache log rotation

This configuration keeps 12 log files and rotates them monthly:

/var/log/httpd/*log {
missingok
notifempty
monthly
rotate 12
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null`
endscript
}

 

This configuration keeps 7 log files and rotates them when they reach 10 MB in size:
/var/log/httpd/*log {
missingok
notifempty
size 10M
rotate 7
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null`
endscript
}

 

   
       
         
 

Copyright © 2006,2007 Linux Box Admin.

 
My NHL fan blog