Tomcat notes

Russell Bateman
22 March 2022
last update:

Apache Tomcat is a server for hosting Java-based web applications. It's also called a servlet container. It supports Java technologies including:

The latest, working version is Tomcat 9. It supports:

Important directories and files:

Web applications are deployed in the form of web application archives (WAR) in the webapps subdirectory of Tomcat. There are three ways to do this:

  1. Static deployment (you have direct access to the server's filesystem):
    1. Stop the server.
    2. Copy the new WAR to webapps.
    3. Restart the server.
  2. Hot deployment (you have direct access to the server's filesystem):
    1. Copy the new WAR to webapps.
  3. Deployment by Tomcat Manager application (you do not have direct access to the server's filesystem, but a username and password for Tomcat Manager application).
    • The web application can be deployed in the webapps subdirectory from the server's filesystem.
    • The web application can be added for deployment by choosing a WAR from the filesystem on the host accessing Tomcat Manager remotely.

Using logrotate to roll catalina.out...

logrotate is a utility that oversees the rotation of most any (compliant) service's log file rotation.

  1. Create the following file on the path /etc/logrotate.d/tomcat. Do not include the comments I'm using here to document the meaning of the configuration.
        daily           # rotate daily
        rotate 90       # keep at most 90 rotations
        compress        # compress catalina.out at rotation
        size 100M       # forces rotation as soon as size exceeds 100M
        copytruncate**  # truncate catalina.out in-place
                          rather than removing it and creating a new one

    * By way of example, this path might be /opt/tomcat/logs/catalina.out.

    ** This is important because Tomcat will not auto-recreate catalina.out as soon as it is missing. Instead, nothing will ever show up in catalina.out until Tomcat is restarted.

  2. If more convenient, you may make of this a single line, for example:
    /opt/tomcat/logs/catalina.out { daily rotate 90 compress size 100M copytruncate }
    It appears that the possible presence or not of an argument is a semantic consideration logrotate takes into account.

  3. Whereupon, the following command will activate the added Tomcat configuration:
    # /usr/sbin/logrotate /etc/logrotate.conf
  4. How this works:
    1. Every night, the cron daemon runs jobs listed in the /etc/cron/daily subdirectory.
    2. Step (a) triggers the /etc/cron.daily/logrotate file (generally shipped in Linux distributions) to run the command:
      # /usr/sbin/logrotate /etc/logrotate.d /etc/logrotate.conf
    3. File /etc/logrotate.conf contains admin-level configuration and refers logrotate to /etc/logrotate.d for more configuration.
    4. Step (c) will engage the new /etc/logrotate.d/tomcat file.
  5. Conclusions? Rotation of catalina.out is possible, but where it's to be done requires the logrotate, cron and other binaries and filesystem enhancements. On purposely lighter containers (Docker, etc.) it may be missing from the minimal Linux base layer chosen.

Useful links