Pivotal Knowledge Base


How to rotate jvm.stdout without restarting Tomcat under vFabric Enterprise Ready Server (ERS) (2008409_draft)

How to rotate jvm.stdout without restarting Tomcat under vFabric Enterprise Ready Server (ERS) (2008409_draft)


The messages that are logged in jvm.stdout are system error messages from the JVM. By default the jvm.stdout file under ERS isn't rotated and may grow very large. To keep this from happening, how can the log be rotated, without having to stop the server? There are some solutions, but the possibilities vary by platform.



The unfortunate answer on this platform is that it's not possible to do this in a supported fashion; the service wrapper used under ERS has no rotation options. Users are encouraged to:
  1. Investigate swallowOutput to minimize output to this file (only server startup/shutdown messages should remain).
  2. Rotate manually during a restart.
  3. Switch to something using a newer wrapper, such as tc Server or Apache Tomcat.


Modify tomcat_startup.sh to pipe JVM output through cronolog (or similar, like rotatelogs):
    1. Obtain the freeware from http://www.cronolog.org/; compile and copy the executable to a convenient location.
    2. Save a copy of the original tomcat_startup.sh.
    3. Modify tomcat_startup.sh to have server commands send JVM output through cronolog. For example:

$catalina_command start >> $server_dir/logs/jvm.stdout 2>&1 &
echo $! > $server_dir/logs/tomcat.pid
$catalina_command stop >> $server_dir/logs/jvm.stdout 2>&1


$catalina_command start 2>&1 | cronolog $server_dir/logs/%Y%m%d.jvm.stdout &
jobs -p > $server_dir/logs/tomcat.pid
$catalina_command stop 2>&1 | cronolog $server_dir/logs/%Y%m%d.jvm.stdout &

Whenever the expanded filename is changed, the log will be rotated. In this example, the log would rotate every 24 hours as the day of the filename changes.

In the second line above, the tomcat.pid capture (used for stopping the JVM later) is changed to jobs -p because $! contains the PID of cronolog, not the JVM process. This specific method is only verified for Linux; the general approach may work for other OSes, but you may need another way to capture the JVM PID.


The following method of re-creating the log file works properly only under Solaris:
    1. cp jvm.stdout jvm.stdout.save
    2. touch jvm.stdout.standby
    3. mv jvm.stdout.standby jvm.stdout
Note that with a very active log it's possible to lose some log entries between step 1 and 3.

Other approaches

The best solution may be to keep from logging here in the first place. Since most of the content that causes jvm.stdout to grow is from applications, use swallowOutput to minimize output to this file. Application output should go to application-specific logs (which are already rotated) and only server-wide messages should remain (usually just from startup/shutdown).

Another solution to investigate is logrotate, available for most Unix-like OSes, which can be run in a cron job to rotate files without modifying how they are written at all. This blog entry gives a Tomcat rotation example using the copytruncate option on Linux; another good blog entry is this collection of tips.
©VMware 2013


Powered by Zendesk