MongoDB server keeps deleted log files open after rotation

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
	compress
	daily
	postrotate
		systemctl kill -s USR1 mongod
	endscript
}

2 Likes