Watch keynotes and sessions from, our virtual developer conference.

MongoDB server keeps deleted log files open after rotation

Hi all,

I made a script to rotate the logs every day, but my log files remain open after the rotation (see attachment).

Even if I restart the mongod processes, this problem will appear in the next few days.

Is there a problem with my script? Or the "kill -SIGUSR1 " command cannot be used when MongoDB is balancing?

Any suggestions or root cause guessing?


$ crontab -l

05 00 * * * /opt/

$ cat /opt/

/bin/kill -SIGUSR1 cat /opt/foo/conf/SB/ 2> /dev/null 2> /dev/null || true
mv /opt/foo/logs/SB/SB11.log.* /opt/foo/logsbk/SB
compress /opt/foo/logsbk/SB/SB11.log.*

/bin/kill -SIGUSR1 cat /opt/foo/conf/SB/ 2> /dev/null 2> /dev/null || true
mv /opt/foo/logs/SB/SB31.log.* /opt/foo/logsbk/SB
compress /opt/foo/logsbk/SB/SB31.log.*

find /opt/foo/logsbk/SB/ -type f -name “*.Z” -mtime +7 -exec rm -rf {} ;

You need to SIGKILL after moving the file. Don’t roll your own just use logrotate

here is my file for logrotate.

# /etc/logrotate.d/mongod
/var/log/mongodb/mongod.log {
	rotate 36500
		systemctl kill -s USR1 mongod

1 Like