Nginx won't reopen log files.
Igor Sysoev
igor at sysoev.ru
Fri Feb 11 10:50:41 MSK 2011
On Thu, Feb 10, 2011 at 06:04:41PM -0600, Michael Lustfield wrote:
> Recently I noticed that logrotate does not actually rotate the files correctly.
> I noticed this in 0.8.54.
>
> The issue seems to be that neither -USR1 or -s reopen will reopen the log files
> after they've been rotated. I'm not sure if this specific to the version
> packaged in Debian but I've seen it as an issue on both Ubuntu and Debian.
>
> Below is what I tried to do to figure out what's going on...
>
> ### Clean slate
> root at liber:/var/log/nginx# /etc/init.d/nginx stop
> Stopping nginx: nginx.
> root at liber:/var/log/nginx# rm *
>
> ### Start Nginx: Creates new log files
> root at liber:/var/log/nginx# /etc/init.d/nginx start
> Starting nginx: nginx.
> root at liber:/var/log/nginx# du access.log access.log.1
> 8 access.log
> du: cannot access `access.log.1': No such file or directory
>
> ### Force logrotate to run (which runs the kill -USR1)
> root at liber:/var/log/nginx# logrotate -f /etc/logrotate.d/nginx
>
> ### Log files rotated
> root at liber:/var/log/nginx# du access.log access.log.1
> 0 access.log
> 8 access.log.1
>
> ### At this point files should already be getting written to the new file
> ### because of the -USR1 in the logrotate script
> root at liber:/var/log/nginx# du access.log access.log.1
> 0 access.log
> 24 access.log.1
>
> ### To make sure the kill was run, we invoke it ourselves
> root at liber:/var/log/nginx# kill -USR1 `cat /var/run/nginx.pid`
>
> ### And see that nginx still isn't using the new file
> root at liber:/var/log/nginx# du access.log access.log.1
> 0 access.log
> 48 access.log.1
>
> ### Using the more proper approach
> root at liber:/var/log/nginx# nginx -s reopen
>
> ### We get the same thing
> root at liber:/var/log/nginx# du access.log access.log.1
> 0 access.log
> 68 access.log.1
>
> ### Trying a less appropriate option....
> root at liber:/var/log/nginx# /etc/init.d/nginx reload
> Reloading nginx configuration: nginx.
>
> ### It's finally reopened the files
> root at liber:/var/log/nginx# du access.log access.log.1
> 20 access.log
> 68 access.log.1
>
>
> Hopefully some smart people here can tell me what I'm doing wrong. :)
What is in error_log ?
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx-devel
mailing list