Few Logrotate Configs
Logrotate is a linux utility which rotates files upon certain conditions.If it's not installed, you can do via apt-get install logrotate
or yum install logrotate
The usual tricky part of logrotate is to reload the process when rotation is complete.
Here I'm storing a few logrotate configurations which are useful for me. Hope they're useful for you too.
NOTE: You should change paths appropriately. All the files go in /etc/logrotate.d/
Mongodb
/var/log/mongodb/*.log {
daily
size 100M
rotate 1
compress
dateext
missingok
notifempty
sharedscripts
copytruncate
postrotate
/bin/kill -SIGUSR1 `cat /vol/mongo/mongod.lock 2> /dev/null` 2> /dev/null || true
endscript
}
Other examples:
/var/logs/randomdump.log
{
size 100k
copytruncate
rotate 0
}
#The above config will rotate the file every 100kb, truncates the log file and deletes the rotated file.
/var/logs/access.log
{
size 100k
copytruncate
rotate 7
}
/var/log/postgresql/*.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
su root root
}