Skip to content

Instantly share code, notes, and snippets.

@isweluiz
Last active October 27, 2022 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isweluiz/b409828f5ddb2380f1edb444cbd54533 to your computer and use it in GitHub Desktop.
Save isweluiz/b409828f5ddb2380f1edb444cbd54533 to your computer and use it in GitHub Desktop.

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.

  1. Create this file
/etc/logrotate.d/tomcat-logs
  1. Copy the following contents into the above file
/opt/tomcat/logs/catalina.out {  
  copytruncate  
  daily  
  rotate 30 
  compress  
  missingok  
} 

About the above configuration:

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

How it works

  • 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 logrotate manually

Run the following command to run the cron job manually

/usr/sbin/logrotate -f  /etc/logrotate.d/tomcat-logs

More logrotate options

To see all logrotate options on your system, see the manual:

man logrotate  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment