Safe log rotation

Igor Sysoev igor at sysoev.ru
Thu Oct 2 06:39:07 UTC 2014


On 02 Oct 2014, at 01:30, jmobile <nginx-forum at nginx.us> wrote:

> Hi,
> 
> I'd like to check how nginx handles command from
> http://wiki.nginx.org/LogRotation
> kill -USR1 `cat /var/run/nginx.pid`
> 
> I'm using it to recreate log files during rotation.
> 
> My question if any loglines can be lost in case time interval between
> physical log files rotation and USR1 is large enough, like seconds? Or if
> load is very high. 
> 
> For example, while I was sending traffic to website with "ab -n 20 -c 10
> http://test-s.mysite.com/static/99$i/logo/test.png > /dev/null 2>&1" in the
> loop, I executed on the web-server this
> 
> tail -n 5 /mnt/vg0-lv0/access.log 
> rm -rf /mnt/vg0-lv0/access.log
> sleep 15; sudo kill -USR1 `cat /var/run/nginx.pid` 
> sleep 2
> head -n 5 /mnt/vg0-lv0/dj-access.log

This is not log rotation but log removal. Try this:

mv /mnt/vg0-lv0/access.log /mnt/vg0-lv0/access.log.OLD
sleep 15;
sudo kill -USR1 `cat /var/run/nginx.pid`
sleep 2
head -n 5 /mnt/vg0-lv0/access.log


-- 
Igor Sysoev
Join us for nginx.conf 2014, October 20-22, San Francisco.
Get 25% off with code NGINXUG: http://nginx.com/nginxconf/



More information about the nginx mailing list