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:
Then paste inside:
cat /var/lib/mongo/mongod.lock 2> /dev/null2> /dev/null || true
That’s it, now your logs will be rotated and compressed and your server diskspace won’t explode.