3

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 '17 at 10:59
  • @Tensibai Could you post this comment as an answer? – 030 Nov 30 '17 at 22:55
2

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

https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Reload_An_Existing_Application

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" ]
do
        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" ]
        then
                echo "Waiting for a bit..."
                sleep 15s
        fi;
done;
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, privacy policy and cookie policy

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