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.
{"signal":10,"error":"User defined signal 1"}when it receives the signal.mongodconfig file look like? Did you check the logrotate status file? (default/var/lib/logrotate.status). Have a look at stackoverflow.com/questions/65320994/… or stackoverflow.com/questions/78345089/… or stackoverflow.com/questions/78092657/…