Keep Jenkins running 24/7 with Service Protector

How to Keep Jenkins Running 24/7 with Service Protector

Automatically restart the Jenkins Windows Service if it crashes or is accidentally shut down. Ensure that your integration environment achieves 100% uptime.

Jenkins is an open-source continuous integration server written in Java. It runs as a Windows Service, as shown here in services.msc:


To protect Jenkins with Service Protector:

  1. Download and install Service Protector, if necessary.

  2. Start Service Protector.

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

    Add Protector

  4. On the General tab, select the Jenkins service in the Service to protect dropdown. You will notice a green circle on the left if the service is already running, as pictured below.

    Jenkins Windows Service: General Tab

  5. If you are interested in monitoring Jenkins and detecting when it stops responding to HTTP requests (or returns a 5XX error), click over to the Monitor tab. We'll set up a failure detection script to tell Service Protector when Jenkins has failed.

    1. Follow these instructions to create the failure detection BAT file. We have called ours check-jenkins.bat and placed it in the Jenkins installation folder, C:\Program Files (x86)\Jenkins.

    2. Check the Whenever it fails a "sanity check" box and click the "..." button to open the Configure Sanity Check window. Enter the full path to the batch file, enclosing the whole value in quotes if it contains at least one space.

      Change the Every controls to 5 minutes or set it to any value that you find appropriate. More time means less frequent checks (and less load on the server), but it also means that errors can go undetected for a longer period.

      Press the OK button to save your sanity check settings.

    Jenkins Windows Service: Monitor Tab

  6. Click the Save button. In a couple of seconds, an entry for Jenkins will show up in the Service Protector window. Jenkins is probably already running but it is not yet being protected by Service Protector (as shown below).

    Jenkins Windows Service: Created

  7. To start protection, choose Protector > Start "Jenkins". The shield icon will go to green to indicate that Jenkins is being protected by Service Protector. Click on the green shield to summon a popup indicating when protection started. (You can also click on the green circle to see information on the service itself.)

    Jenkins Windows Service: Running

  8. That's it! Next time your computer boots, Jenkins will start as normal and Service Protector will begin monitoring the service to promptly restart it if it fails or stops for any reason.

    We encourage you to edit Jenkins in Service Protector and check out the many other settings that may be appropriate for your environment. For example, send an email when the service fails, restart Jenkins during the wee hours to keep performance snappy, restart Jenkins if it hogs the CPU and much more.



Trouble protecting the Jenkins Windows Service?