If catalina.out becomes 2GB in size or more, tomcat can crashes and fails to start without any error message. To avoid this scenario you should rotate catalina.out frequently. This article describes how to setup auto rotation of catalina.out on a linux/unix machine.
- Create this file
/etc/logrotate.d/tomcat-logs
- Copy the following contents into the above file
/opt/tomcat/logs/catalina.out {
copytruncate
daily
rotate 30
compress
missingok
}
Make sure that the path /opt/tomcat/logs/catalina.out above is adjusted to point to your tomcat’s catalina.out daily - rotates the catalina.out daily rotate – keeps at most 30 log files compress – compressesthe rotated files
- Every night the cron daemon runs jobs listed in the /etc/cron.daily/ directory
- This triggers the /etc/cron.daily/logrotate file which is generally shipped with linux installations. It runs the command “/usr/sbin/logrotate /etc/logrotate.conf“
- The /etc/logrotate.conf includes all scripts in the/etc/logrotate.d/ directory.
- This triggers the /etc/logrotate.d/tomcat-logs file that you wrote in the previous step.
Run the following command to run the cron job manually
/usr/sbin/logrotate -f /etc/logrotate.d/tomcat-logs
To see all logrotate options on your system, see the manual:
man logrotate