Java Service Wrapper is a set of scripts that runs your Tomcat container as a daemon. This wrapper helps maximize your uptime by monitoring your JVM and restarting your container when it senses trouble from the JVM.
Your Tomcat container can be run by simply executing yourdomain.com/tomcat/bin/tomcat console.
This wrapper contains fairly standard daemon scripts. They accept console, start, stop, restart, and dump commands. The start, stop, and restart commands are common to most daemon scripts and are used to control the wrapper and its application as a daemon process. The status command can be used to find out whether or not the wrapper is currently running. The console command will launch the wrapper in the current shell, making it possible to kill the application with CTRL-C. The final command, dump, will send a kill -3 signal to the wrapper causing the its JVM to do a full thread dump.
Running in a Console
The application can now be run by simply executing bin/myapp console. Because of the way the Wrapper script sets its current directory, it is not necessary to run this script from within the bin directory.
$ cd yourdomain.com/tomcat/bin/
$ ./tomcat console
Running My Application...
wrapper | --> Wrapper Started as Console
wrapper | Launching a JVM...
jvm 1 | Wrapper (Version 3.x.x)
jvm 1 |
When running using the console command, output from the JVM will be visible in the console.
The application can be terminated by hitting CTRL-C in the command window. This will cause the Wrapper to shut down the application cleanly.
As you will see if you omit a command, the scripts shipped with the wrapper are fairly standard daemon scripts. They accept console, start, stop, restart, status, and dump commands. The start, stop, and restart commands are common to most daemon scripts and are used to control the wrapper and its application as a daemon process. The status command can be used to find out whether or not the wrapper is currently running. The console command will launch the wrapper in the current shell, making it possible to kill the application with CTRL-C. The final command, dump, will send a kill -3 signal to the wrapper causing the its JVM to do a full thread dump.
Running as a Daemon Process
The application can be run as a detatched daemon process by executing the script using the start command.
$ cd yourdomain.com/tomcat/bin/
$ ./tomcat start
Running My Application...
When running using the start command, output from the JVM will only be visible
by viewing the wrapper.log file using tail -f wrapper.log.
Because the application is running as a detatched process, it can not be terminated using CTRL-C and will continue to run even if the console is closed.
To stop the application rerun the script using the stop command.
Example command with output:
$ cd yourdomain.com/tomcat/bin/
$ ./tomcat stop
Stopping tomcat Application.
Stopped tomcat Application
Benefits of using this Wrapper
Application Reliability. As the use of Java expands, applications have been written to provide a variety of mission critical services. These services must be able to provide a high level of reliability. In an ideal world, only software which is 100% bug free will ever be released and installed. However, history has shown this not to be the case. Almost every application suffers from quality issues at one point or another during their life-cycle. Applications hang, crash, run out of memory or suffer from any number of problems. Where possible, problems are fixed quickly without significant service outages. There are times, however, when fixing a problem can be prohibitively expensive or impossible to solve in a short time period.
The Wrapper monitors a JVM process and automatically restarts it if it that the JVM has crashed or hung. This process takes just a few seconds once the Wrapper has decided there is a problem. There is also a way to configure the Wrapper to monitor the console output of a JVM and react to certain strings by restarting or shutting down the JVM.
While these features will not make every problem go away, they will help you to sleep easier knowing that if there is a problem, the Wrapper will be there to keep things up and running until you can get into the office to check the logs. Say goodbye to that pager!! (Or as so as not to date myself, that cell phone!)
For more information about the Tomcat Wrapper, click here
|