0

I'm trying to use LogRotate to manage my MongoDB logs because they were growing too large. My goal is to:

  • Create a new log file daily

  • Compress old logs

  • Keep logs for only the last 14 days

  • Delete older ones automatically

Here is my current LogRotate configuration for MongoDB (/etc/logrotate.d/mongod):

bash Copy Edit /var/log/mongodb/mongod.log { daily rotate 14 compress delaycompress missingok notifempty create 640 mongodb mongodb sharedscripts postrotate /bin/kill -SIGUSR1 $(pidof mongod) 2>/dev/null || true endscript } 

The problem: A new log file is only created when I reboot the system.

Until then, MongoDB keeps writing to the same log file.

It does not rotate daily, even though I’ve set daily and tried various combinations.

I also noticed it starts writing only after I log into the server.

Question: Is there anything wrong with my config? Or am I missing a step to make MongoDB rotate logs daily as intended? I'd really appreciate any help or suggestions.

2

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.