0

I have installed the mongodb in my server and i have added the log rotation policy in the mongod.conf where

systemLog: destination: file logAppend: true logRotate: reopen path: /var/log/mongodb/mongod.log 

I have also installed the logrotate in my server and added the policy in this

sudo nano /etc/logrotate.d/mongodb /var/mongodb/log/*.log { rotate 10 daily dateext dateformat %Y-%m-%d-%s dateyesterday size 10000M missingok create 600 mongodb mongodb delaycompress compress sharedscripts postrotate /bin/kill -SIGUSR1 $(cat /var/run/mongodb.pid) endscript } 

I have given the permissions to mongodb as well , file is being created but the logs are not there in those files

I tried giving the permission to logs of mongodb but still no success

1 Answer 1

0

You defined logfile path: /var/log/mongodb/mongod.log, however your logrotate uses /var/mongodb/log/*.log. You mistake the folder names.

Another issue: by default logrotate uses statefile /var/lib/logrotate.status which may require according privileges. Use logrotate --state <statefile> for a different statefile.

Note, for the postscript I would suggest to use

if /usr/sbin/pidof -s mongod > /dev/null ; then kill -USR1 $( /usr/sbin/pidof mongod ) ; fi 

It does not throw an error if your mongod is not running.

Sign up to request clarification or add additional context in comments.

2 Comments

Use logrotate --state <statefile> for a different statefile. im not able to get you ,i have changed the path of the mongodb logs and given the permission of to logrotate.status but other logrotate --state <statefile> not able to understand
If you have write permissions on /var/lib/logrotate.status then you are fine and you can ignore this hint. But as said, by default folder /var/lib/ is owned by root and has u=rwx,go=rx, thus by default logrotate fails if you run it as non-root user.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.