I like to stop Tomcat before redeployment, manually clean out the old wars and all the logs, then restart the server. To do that from Jenkins, I have been using the SSH plugin and call sudo service tomcat stop/start and it works... sometimes. Other times the stop works but it fails to restart but the job still erroneously succeeds.

Is there an alternative to restarting Tomcat to SSH, especially when invoked from Jenkins. E.g. can I set up something like xinetd to make these admin functins somewhat of web services. Automating SSH connection from Jenkins is sort of a crapchute.

  • Just test your app after start, even if tomcat were to start, your app may not start properly, so your job should end up with a smoke test on the application itself and this would solve your overall problem.
    – Tensibai
    Nov 15, 2017 at 10:59
  • @Tensibai Could you post this comment as an answer?
    – 030
    Nov 30, 2017 at 22:55

1 Answer 1


If you install the manager webapp with a default set up of tomcat then it is possible to use this to install and restart applications, see


I feel that you are asking the wrong question however. The problem is not how to restart Tomcat but how to be sure that it has restarted

Set a host, tomcat_port and check path then use shell code like this

while [ "$response_code" != "200" ]
        echo "Checking whether tomcat (${host}:${tomcat_port}/$check) is alive..."
        response_code=`curl -sL -w "%{http_code}" "http://${host}:${tomcat_port}/${check}" -o /dev/null`
        echo "Received response code $response_code"
        if [ "$response_code" != "200" ]
                echo "Waiting for a bit..."
                sleep 15s
echo "Tomcat is alive!"

This will wait until the Tomcat comes back - or the containing Jenkins job will time out eventually

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.