MongoDB For Ubuntu Doesn’t Install A Logrotate Script

This tripped me up before, one of my servers very rapidly ran out of disk space and I had to figure out why – I scanned the server and found the culprit directory was /var/log/mongodb/ and there was a single multi GB log file in there.

I checked /etc/logrotate.d/ and indeed the Ubuntu MongoDB package directly from mongodb.org (mongodb-10gen) doesn’t install a lot rotate script (which is rather perilous).

So as I wanted to keep logs on rather than disabling them totally, I rolled up a logrotate script. All you need to do is:

nano /etc/logrotate.d/mongodb

Then paste inside:

/var/log/mongodb/*.log {
daily
rotate 30
compress
dateext
missingok
notifempty
sharedscripts
postrotate
/bin/kill -SIGUSR1 cat /var/lib/mongo/mongod.lock 2> /dev/null 2> /dev/null || true
endscript
}

That’s it, now your logs will be rotated and compressed and your server diskspace won’t explode.

Comments

comments

Subscribe

You can subscribe via e-mail to get my posts in your Inbox, or stalk me on numerous other platforms.

, , , , ,


Comments are closed.
 
Keep up with me on Social Media by following me below - Thanks so much!