Tomcat servers have the ability to fire lifecycle events. These events include the startup and shutdown of a server. Administrators can write scripts to automatically run when these events occur. For example, scripts can start a third party server when an instance starts. Logically, another script would shut down the third party server when the instance shuts down. The scripts must be located in the instance/bin directory and use the following naming conventions.
Table 1. Automated lifecycle scripts
Script
Lifecycle event
scriptPrefix_starting.bat|sh
Executes when the Tomcat container is started but before any web application context are created.
scriptPrefix_started.bat|sh
Executes when the Tomcat container is started and after all web application contexts are created.
scriptPrefix_stopping.bat|sh
Executes before stopping an instance
scriptPrefix_stopped.bat|sh
Executes after stopping an instance.
Note: Replace the scriptPrefix with a unique name for each instance.
Scripts execute inline
The startup and shutdown event scripts execute in-line which means the Tomcat startup/shutdown process waits for the event script to complete before continuing. If a script hangs it prevents the lifecycle event from completing.
Logs and errors
The standard server logs, located in the instance/logs directory, tracks when the scripts are called. If errors are raised by the script, those errors do not interrupt the standard server startup or shutdown. Administrators are responsible for catching errors in their scripts and writing those errors to a script specific log file in the instance/logs directory.