I need to rotate some Tomcat logs in Solaris. When I try to use logadm with the -c option, the rotation seems to occur correctly, but then catalina.out becomes a block of nulls the same size as the rotated part, and new data is written after these nulls. It's as if the file position pointer never moved, and Tomcat's output keeps advancing from the same position.
As a result, catalina.out continues to grow. The leading block of nulls grows with every rotation event.
When it works, this is the most convenient log rotation solution I know of, because you don't have to modify catalina.sh. But it isn't working, and the alternative — piping the output through Apache logrotate — requires modifying catalina.sh, which I'd rather not do. It means another local change to track every time we update Tomcat.
Best Answer
Actually,
catalina.sh
does intend to opencatalina.out
withO_APPEND
:>> "$CATALINA_OUT" 2>&1 &
The root cause is the shell:
#!/bin/sh
. Solaris' default shell (/bin/sh
) does not interpret>>
correctly to open the output file withO_APPEND
.This is not a problem on Linux. You can work around it for Solaris with a standards compliant shell:
/usr/xpg4/bin/sh
(seeman sh
)Modify
catalina.sh
and replace#!/bin/sh
with#!/usr/xpg4/bin/sh
. The disadvantage is that every time you update Tomcat, you need to redo it.It is easy to verify whether
catalina.out
is opened withO_APPEND
or not using thepfiles
command.You can see that
/usr/xpg4/bin/sh
openscatalina.out
withO_APPEND
.