Nginx, Logrotate and Gentoo: Infinite loop problem and solution

Written by
Date: 2011-12-25 18:03:00 00:00

Today I've found that my CPU was throttling at 100%. The culprit was logrotate, or at least that was what I thought when I took a look at htop and saw that logrotate had been running at 100% for 10 hours straight.

I then used du, in the /var/log/ folder to find which was the folder that was so big to have logrotate so busy, it happened to be nginx.

After reading the configuration files, I found the problem. In the file /etc/logrotate.d/nginx that was the default installed by Nginx I could see this contents:

# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/www-servers/nginx/files/nginx.logrotate,v 1.2 2011/04/08 08:32:20 hollow Exp $

/var/log/nginx/* {
	missingok
	sharedscripts
	postrotate
		test -r /var/run/nginx.pid && kill -USR1 `cat /var/run/nginx.pid`
	endscript
}

Now, the problem was in this line /var/log/nginx/* that was causing that all files enter into the rotation routine, even the already rotated ones, and after some months running there were enough files there to send my CPU to throttle to 100% use.

I have changed that line to: /var/log/nginx/*.log and in the /etc/nginx/nginx.conf file I made sure that all log files have a .log in the end.

Hope this may help someone sometime.