<p>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 </p>

<p><a href="https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Reload_An_Existing_Application" rel="nofollow noreferrer">https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Reload_An_Existing_Application</a></p>

<p>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</p>

<p>Set a host, tomcat_port and check path then use shell code like this</p>

<pre><code>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!"
</code></pre>

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

CC BY-SA 3.0
2018-02-08T15:31:04.630Z
2018-02-08T15:31:04.630Z
Vorsprung
<p>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 <code>Jenkins</code>, I have been using the <a href="https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin" rel="nofollow noreferrer"><code>SSH plugin</code></a> and call <code>sudo service tomcat stop/start</code> and it works... sometimes. Other times the stop works but it fails to restart but the job still erroneously succeeds.</p>

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

CC BY-SA 3.0
2017-11-15T10:59:03.257Z
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
CC BY-SA 3.0
2017-11-30T22:55:58.107Z
@Tensibai Could you post this comment as an answer?
030
<jenkins><tomcat>
Remote starting/stopping Tomcat from Jenkins
amphibient
# Remote starting/stopping Tomcat from Jenkins

(Asked by: username_0 on 2017-11-14)

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`](https://wiki.jenkins.io/display/JENKINS/Publish+Over+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.

**Tags:** jenkins, tomcat

> **Comments:**
> **username_1**: 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.  
> **username_2**: @username_1 Could you post this comment as an answer?  

---

## 1 answers

### Answer by username_3 on 2018-02-08. Score: 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


---

