How to logrotate tomcat's catalina.out

The tomcat introduced in this article was installed by chef.
But it will be a usable way even if it is not so.

A catalina.out of tomcat can be set with a configuration file called conf/logging.properties and basiclly it has already setuped logs rotation with a date.
For this setting, catalina.out logs added date suffix are output.
But tomcat keeps logging to catalina.out after log rotation.
In near future, size of catalina.out gets bloated and it will be consumed local disk spaces.
I would like to introduce how to deal with such cases.

Edit the configuration file of the tomcat start script.

  • vim /etc/init.d/tomcat7

First, comment out the following part.

$SU "$TOMCAT_USER" -c "touch $CATALINA_OUT"

#$SU "$TOMCAT_USER" -c "touch $CATALINA_OUT"

Next, change it to use rotatelogs command.

org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 &
echo \$! > "$CATALINA_PID"

org.apache.catalina.startup.Bootstrap "$@" start >/dev/null 2>&1 &
echo \$! > "$CATALINA_PID" | /usr/sbin/rotatelogs $CATALINA_BASE/logs/catalina.%Y-%m-%d.log 86400 540

Restart the process to reflect the setting.

  • service tomcat7 restart

Confirm that there is no process grabbing catalina.out.

  • lsof | grep catalina.out

You can finally delete the bloated catalina.out.

  • rm catalina.out

If the disk capacity does not decrease, some process grabs catalina.out.
Check process with lsof command and kill it.

Please change the path of the rotetelogs command according to your environment.
The value of 86400 is a setting to rotate at 0 o’clock everyday.
Change that value as you like.

If you do not have /etc/init.d/tomcat7 configuration file, search and edit /usr/local/tomcat/bin/catalina.sh etc too.

Comments

Popular posts from this blog

Detect Bluetooth LE Device with BlueZ on RaspberryPi

What I did until many slimes spawn on slime chunk

Major Maven goals