You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Cervenka, Tom" <TC...@uillinois.edu> on 2005/02/14 16:06:55 UTC

Can't do log rotation on windows

I've got tomcat 4 running on a win2003 server and it spits it's log
messages to a catalina.out file. Once a day I want to rotate the log -
copy it, zip up the copy and truncate the original. I do this on linux
with a simple shell script. Tomcat is running during all of this and has
its mitts into the file but linux doesn't seem to care. Different story
on windows, however. The short story is that catalina.out is corrupted
big time.

 

I've had 2 ideas to work around this. One is to stop the service before
truncating the file and start it up again afterwards. This works but
win2003 can't always restart the service, like 50% of the time. So I've
given up on this route. I need a solution that works while tomcat is
running.

 

The only idea I've had for this is to try to get tomcat to use a
filelogger like it provides for it's contexts. I made the changes to
server.xml but then never did doodly squat. I know I'm not the only one
that's had trouble doing this on windows as I've seen other notes to
list about it. I posted a note a while back (attached) but no response.
Is it because no one runs tomcat on windows?

 

-Tom


AW: Can't do log rotation on windows

Posted by Steffen Heil <li...@steffen-heil.de>.
Hi

> I've got tomcat 4 running on a win2003 server and it spits it's log
messages to a catalina.out file. Once a day I want to rotate the log - copy
it, zip up the copy and truncate the original. I do this on linux with a
simple shell script. Tomcat is running during all of this and has its mitts
into the file but linux doesn't seem to care. Different story on windows,
however. The short story is that catalina.out is corrupted big time.

Lesson: Never modify a file that another process is actively writing to.
This is not supposed to work. Neighter on windows, nor on linux. Luck for
you, that this works on Linux.
The os should lock that file inbetween, but since stdout is redirected
different way on both oses, there are different possibilities.

> One is to stop the service before truncating the file and start it up
again afterwards. This works but win2003 can't always restart the service,
like 50% of the time. So I've given up on this route. I need a solution that
works while tomcat is running.

Propably you got "bind: port in use". Stop the service, wait some time, do
your work, restart the service. This should work. At least it works here.
Basically to stop means to tell the service that it shall stop. Tomcat might
take some more time. Furthermore, the os might take some time to realise,
that the socket is available again.

>  The only idea I've had for this is to try to get tomcat to use a
filelogger like it provides for it's contexts. I made the changes to
server.xml but then never did doodly squat. I know I'm not the only one
that's had trouble doing this on windows as I've seen other notes to list
about it. I posted a note a while back (attached) but no response. Is it
because no one runs tomcat on windows?

This would be the best way, but involved changing your logging scheme in
your application. stdout redirection is not possible through loggers, afaik.

Regards
  Steffen