# Log rotation on windows?

**URL:** <https://www.ruby-forum.com/t/log-rotation-on-windows/193723>\
**Category:** NGINX\
**Created:** [August 23, 2010, 3:01pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723 "2010-08-23T15:01:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 23, 2010, 3:01pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/1 "2010-08-23T15:01:43Z")

</div>

I’ve searched a lot for this but I haven’t found any information.  
On linux you can do a log rotation by sending the USR1 signal to the  
process.  
Is there a similar way to do this on windows?

Thanks.

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 23, 2010, 4:29pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/2 "2010-08-23T16:29:33Z")

</div>

On Mon, Aug 23, 2010 at 8:00 PM, Arthur B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’ve searched a lot for this but I haven’t found any information.  
> On linux you can do a log rotation by sending the USR1 signal to the  
> process.  
> Is there a similar way to do this on windows?  
> Thanks.

nginx -s reopen

?

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 23, 2010, 4:45pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/3 "2010-08-23T16:45:22Z")

</div>

I get this error:

C:\nginx\>nginx -s reopen  
[error]: OpenEvent(“ngx\_reopen\_1884”) failed (2: The system cannot find  
the  
file specified)

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 23, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/4 "2010-08-23T16:54:44Z")

</div>

C:\nginx\>tasklist /fi “imagename eq nginx”  
INFO: No tasks are running which match the specified criteria.

C:\nginx\>tasklist /fi “imagename eq nginx.exe”

# Image Name PID Session Name Session# Mem Usage ========================= ======== ================ ===========

nginx.exe 1884 Services 0  
4,460 K  
nginx.exe 1752 Services 0  
5,512 K

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 23, 2010, 4:51pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/5 "2010-08-23T16:51:48Z")

</div>

On Mon, Aug 23, 2010 at 10:44:21AM -0400, Arthur B. wrote:

> I get this error:
> 
> C:\nginx\>nginx -s reopen  
> [error]: OpenEvent(“ngx\_reopen\_1884”) failed (2: The system cannot find the  
> file specified)

What does

tasklist /fi “imagename eq nginx.exe”

show ?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 23, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/6 "2010-08-23T16:57:40Z")

</div>

On Mon, Aug 23, 2010 at 10:53:38AM -0400, Arthur B. wrote:

> C:\nginx\>tasklist /fi “imagename eq nginx”  
> INFO: No tasks are running which match the specified criteria.
> 
> C:\nginx\>tasklist /fi “imagename eq nginx.exe”
> 
> Image Name PID Session Name Session# Mem Usage  
> ========================= ======== ================ =========== ============  
> nginx.exe 1884 Services 0 4,460 K  
> nginx.exe 1752 Services 0 5,512 K

Strange, there is a process with 1884 pid. The event should exist.  
Could you terminate the nginx processes, then start nginx again and try  
to run “nginx -s reopen” ?

> > * * *
> > 
> > nginx mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 24, 2010, 1:04pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/7 "2010-08-24T13:04:21Z")

</div>

My apologies: I see now that this behavior is clearly documented here:  
[nginx for Windows](http://nginx.org/en/docs/windows.html) it was confusing to me whether  
[wiki.nginx.org](http://wiki.nginx.org) or [nginx.org](http://nginx.org) is the official documentation page.  
Thanks for this great software!  
I was able to replace 4 load balanced Apache servers that could not  
handle a  
high request load (\>1000 requests per second) with one nginx instance on  
a  
single server that could handle all that load with a small amount of  
memory  
and staying at around 10% cpu. Is nginx on windows still considered  
inferior in performance to the linux version? Despite that, it seems to  
blow away apache on windows.

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 24, 2010, 1:56pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/8 "2010-08-24T13:56:28Z")

</div>

On Tue, Aug 24, 2010 at 07:03:43AM -0400, Arthur B. wrote:

> My apologies: I see now that this behavior is clearly documented here:  
> [nginx for Windows](http://nginx.org/en/docs/windows.html) it was confusing to me whether  
> [wiki.nginx.org](http://wiki.nginx.org) or [nginx.org](http://nginx.org) is the official documentation page.\

nginx can run as a service itself, but it should be run by another  
utility. Probably nginx should use "Global" prefix, i.e.  
“Global\ngx\_reopen\_XXX”, because srvany/etc may change session.  
Tomorrow I will make a test-build with this prefix to test it.

> > I tried that and it does not work either, but I’ve found that if I run  
> > anywhere on the wiki or faq. I guess it’s supposed to be obvious?)
> > 
> > > > Image Name PID Session Name Session# Mem  
> > > > to run “nginx -s reopen” ?
> > > > 
> > > > > the  
> > > > > Igor S.  
> > > > > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > > > > [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 23, 2010, 5:15pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/9 "2010-08-23T17:15:14Z")

</div>

I tried that and it does not work either, but I’ve found that if I run  
nginx  
directly from the command line, it does work.

I am using a windows service wrapper so that nginx can continue to run  
when  
I’m logged off (as documented here  
[http://misterdai.wordpress.com/2009/10/16/nginx-windows-service/](http://misterdai.wordpress.com/2009/10/16/nginx-windows-service/))  
In fact, none of the -s commands work when I’m running it under a  
service.  
Any ideas why not? I tried it both under an administrator account and  
the  
actual account that it is running under as a service…

It wasn’t clear to me that “-s reopen” was for reopening the log files  
(not  
anywhere on the wiki or faq. I guess it’s supposed to be obvious?)

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 24, 2010, 2:06pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/10 "2010-08-24T14:06:25Z")

</div>

On Tue, Aug 24, 2010 at 03:55:29PM +0400, Igor S. wrote:

> On Tue, Aug 24, 2010 at 07:03:43AM -0400, Arthur B. wrote:
> 
> > My apologies: I see now that this behavior is clearly documented here:  
> > [nginx for Windows](http://nginx.org/en/docs/windows.html) it was confusing to me whether  
> > [wiki.nginx.org](http://wiki.nginx.org) or [nginx.org](http://nginx.org) is the official documentation page.\
> 
> nginx can run as a service itself, but it should be run by another

nginx can NOT run as a service itself, but it should be run by another

> utility. Probably nginx should use "Global" prefix, i.e.  
> “Global\ngx\_reopen\_XXX”, because srvany/etc may change session.  
> Tomorrow I will make a test-build with this prefix to test it.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 24, 2010, 2:18pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/11 "2010-08-24T14:18:43Z")

</div>

Yes, I am using the winsw wrapper to run nginx as a server. It’s very  
lightweight and easy to use.  
[http://projectkenai.com/projects/winsw](http://projectkenai.com/projects/winsw)  
[http://projectkenai.com/projects/winsw](http://projectkenai.com/projects/winsw)By the way, this project is MIT  
licensed, so I think that it would be quite easy to add it to the nginx  
code  
base.  
[http://misterdai.wordpress.com/2009/10/16/nginx-windows-service/](http://misterdai.wordpress.com/2009/10/16/nginx-windows-service/)  
explains  
fully how to use winsw with nginx.

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 24, 2010, 2:04pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/12 "2010-08-24T14:04:40Z")

</div>

Thank you. I would be happy to test this build for you as well.

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 25, 2010, 2:07pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/13 "2010-08-25T14:07:49Z")

</div>

I found the ultimate solution to my problem: Switch to Linux 🙂

One more question: On Linux, which command is better to rotate log  
files?

nginx -s reopen

or

kill -USR1

I think using nginx -s reopen is better because its more clear and you  
don’t  
have to grab the pid. On the other hand, using kill may be more unixy  
and  
work better with some existing system rotation scripts. But I think  
that’s  
moot anyway because using the USR1 signal to rotate logs is not really  
standard. It probably doesn’t really matter. I’m thinking that using  
kill  
to rotate the logs is just sort of a “legacy” way of doing it before the  
-s  
reopen option was added…

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 25, 2010, 2:30pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/14 "2010-08-25T14:30:04Z")

</div>

On Tue, Aug 24, 2010 at 08:03:49AM -0400, Arthur B. wrote:

> Thank you. I would be happy to test this build for you as well.

Could you test this: [http://nginx.org/tmp/nginx-0.8.50.zip](http://nginx.org/tmp/nginx-0.8.50.zip) ?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 25, 2010, 3:12pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/15 "2010-08-25T15:12:14Z")

</div>

On Wed, Aug 25, 2010 at 8:28 AM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Tue, Aug 24, 2010 at 08:03:49AM -0400, Arthur B. wrote:
> 
> > Thank you. I would be happy to test this build for you as well.
> 
> Could you test this: [http://nginx.org/tmp/nginx-0.8.50.zip](http://nginx.org/tmp/nginx-0.8.50.zip) ?

C:\nginx-0.8.50\>tasklist /fi “imagename eq nginx.exe”

# Image Name PID Session Name Session# Mem Usage ========================= ======== ================ ===========

nginx.exe 6824 Services 0  
4,808 K  
nginx.exe 5328 Services 0  
5,132 K

C:\nginx-0.8.50\>nginx -s reopen  
[error]: OpenEvent(“Global\ngx\_reopen\_6824”) failed (5: Access is  
denied)

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 25, 2010, 2:35pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/16 "2010-08-25T14:35:21Z")

</div>

On Wed, Aug 25, 2010 at 08:06:41AM -0400, Arthur B. wrote:

> I found the ultimate solution to my problem: Switch to Linux 🙂

Yes, Linux is much more preferable than Windows for nginx.

> work better with some existing system rotation scripts. But I think that’s  
> moot anyway because using the USR1 signal to rotate logs is not really  
> standard. It probably doesn’t really matter. I’m thinking that using kill  
> to rotate the logs is just sort of a “legacy” way of doing it before the -s  
> reopen option was added…

We usually use the kill. “nginx -s reopen” has to grab the pid using  
nginx.conf, because it needs to know master process pid.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 25, 2010, 3:46pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/17 "2010-08-25T15:46:47Z")

</div>

On Wed, Aug 25, 2010 at 7:31 PM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> We usually use the kill. “nginx -s reopen” has to grab the pid using  
> nginx.conf, because it needs to know master process pid.

actually, using `nginx -s reopen -c /path/to/config` is usually more  
reliable as there’s no need to check/find the path to pidfile (unless  
using pkill but then that’d trigger all nginx master servers when  
there are more than one running (no reason to, but who knows?))

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 25, 2010, 3:47pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/18 "2010-08-25T15:47:57Z")

</div>

On Wed, Aug 25, 2010 at 9:18 AM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > >
> 
> 5,132 K
> 
> > C:\nginx-0.8.50\>nginx -s reopen  
> > [error]: OpenEvent(“Global\ngx\_reopen\_6824”) failed (5: Access is denied)
> 
> It’s better. Could you run “nginx -s reopen” as the same user as run by  
> WinSW ?

That works! Just have to make sure to use the -p option too if you run  
the  
command from another path.

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [August 25, 2010, 3:19pm UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/19 "2010-08-25T15:19:16Z")

</div>

On Wed, Aug 25, 2010 at 09:11:22AM -0400, Arthur B. wrote:

> C:\nginx-0.8.50\>tasklist /fi “imagename eq nginx.exe”
> 
> Image Name PID Session Name Session# Mem Usage  
> ========================= ======== ================ =========== ============  
> nginx.exe 6824 Services 0 4,808 K  
> nginx.exe 5328 Services 0 5,132 K
> 
> C:\nginx-0.8.50\>nginx -s reopen  
> [error]: OpenEvent(“Global\ngx\_reopen\_6824”) failed (5: Access is denied)

It’s better. Could you run “nginx -s reopen” as the same user as run by  
WinSW ?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![ruhtra01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/76d3ee/32.png) [@ruhtra01](https://www.ruby-forum.com/u/ruhtra01)\
**Post date:** [February 4, 2011, 9:53am UTC](https://www.ruby-forum.com/t/log-rotation-on-windows/193723/20 "2011-02-04T09:53:20Z")

</div>

> **[pyrotate](https://sourceforge.net/projects/pyrotate/)**
>
> Download pyrotate for free. English:
> Pyrotate is Python program for log files rotation. It uses any external archiver such as Winrar, 7-zip or gzip for compress and may rotate files in GNU/Linux logrotate's style.

Posted at Nginx Forum:

> **[Re: log rotation on windows?](https://forum.nginx.org/read.php?2,122714,172133#msg-172133)**
>
> I've searched a lot for this but I haven't found any information. On linux you can do a log rotation by sending the USR1 signal to the process. Is there a similar way to do this on windows? Thanks. \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_...

[Next page](https://www.ruby-forum.com/t/log-rotation-on-windows/193723.md?page=2)
