Keep Apache Tomcat Windows Service running 24/7

How to Keep Tomcat Windows Service Running 24/7 with Service Protector

Quickly auto-restart Tomcat when it crashes, gets stuck or stops serving web pages. Ensure 100% uptime for your java web applications today!

Tomcat is a popular, open source Java Servlet engine developed by the Apache Foundation.

To monitor & protect Tomcat with Service Protector:

  1. Download, install, and configure Tomcat as a Windows Service, if necessary. We have installed version 7.0.35 on our Windows Server 2008 R2 server.

  2. Download and install Service Protector, if necessary.

  3. Start Service Protector.

  4. Select Protector > Add to open the Add Protector window:

    Add Protector

  5. On the General tab:

    • In the Service to protect field, choose the Tomcat windows service. This will be named Apache Tomcat X.Y TomcatX, where X.Y represents the software's version number. Since we have installed Tomcat version 7.0.35, our service is named Apache Tomcat 7.0 Tomcat7.

      You will notice a green circle to the left of the name if Tomcat is already running, as pictured below.

    Tomcat Windows Service: General Tab

  6. Click over to the Monitor tab, where we will set up a failure detection script to tell Service Protector when Tomcat has failed and is not serving web pages.

    1. Follow these instructions to create the failure detection BAT file. We have called ours check-tomcat.bat and placed it in a folder called C:\TomcatTools.

    2. Check the Whenever it fails a "sanity check" box. Click the ... button and specify the full path to the batch file.

    3. Specify how often to check. The default of 30 seconds may be too frequent, so we changed it to 5 minutes.

    Tomcat Windows Service: Monitor Tab

  7. If you find that the Tomcat windows service occasionally gets stuck in the "Stopping" or "Starting" state, click over to the Extras tab and check the corresponding options.

    Tomcat Windows Service: Extras Tab

  8. Click the Save button. In a second or two, an entry for Apache Tomcat will show up in the Service Protector window. Here the Tomcat service is already running but it's not yet being monitored by Service Protector (hence the red shield).

    Tomcat Windows Service: Created

  9. To start protection, choose Protector > Start "Apache Tomcat 7.0 Tomcat7". The shield icon will go to green to indicate that the Tomcat service is being protected:

    Tomcat Windows Service: Protected

  10. That's it! Next time your computer boots, Tomcat will start (as normal) and Service Protector will begin watching the service to promptly restart it if it stops for any reason.

    We encourage you to edit Tomcat in Service Protector and check out the many other settings that may be appropriate for your environment. For example, send email alerts when the service fails, restart Tomcat nightly to cure memory leaks, detect CPU hogging, and much more.

Trouble protecting the Tomcat Windows Service?