Friday, February 13, 2009

linux tool: logrotate

logrotate is very useful tool in linux.

see I run sphinx searchd and it creates logs. it would become very large if I leave it alone.
and I have another cron script like theschwartz_worker.pl and it writes the debug info into file when I use $job->debug

those are very common situation. and with logrotate, it becomes simple.
place your files into /etc/logrotate.d/
like /etc/logrotate.d/searchd
/var/log/searchd/foorum.log {
weekly
rotate 5
compress
delaycompress
create 640 root root
postrotate
killall -SIGUSR1 searchd
endscript
}
like /etc/logrotate.d/theschwartz
/var/log/theschwartz.log {
weekly
rotate 10
compress
delaycompress
create 640 root root
}
After you write your conf, you can start test by:
$> logrotate -d /etc/logrotate.d/searchd
rotating pattern: /var/log/searchd/foorum.log weekly (5 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/searchd/foorum.log
log does not need rotating
not running postrotate script, since no logs were rotated

google around to find more details. or just man logrotate.

Thanks.

Labels: ,