Failure To Shutdown Embedded Tomcat Instance In Bamboo
Asked by Joseph Cooper:

I am attempting to run integration tests on an embedded tomcat instance in a multi-module maven project. I am using the tomcat7-maven-plugin configured as follows:

```
&lt;plugin&gt;					&lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;					&lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;					&lt;version&gt;2.2&lt;/version&gt;					&lt;configuration&gt;						&lt;server&gt;my-tomcat&lt;/server&gt;						&lt;path&gt;/svc&lt;/path&gt;						&lt;url&gt;http://localhost:8080/manager/text&lt;/url&gt;					&lt;/configuration&gt;					&lt;dependencies&gt;						&lt;dependency&gt;							&lt;groupId&gt;com.oracle&lt;/groupId&gt;							&lt;artifactId&gt;ojdbc6&lt;/artifactId&gt;							&lt;version&gt;11.2.0&lt;/version&gt;							&lt;scope&gt;runtime&lt;/scope&gt;						&lt;/dependency&gt;						&lt;dependency&gt;							&lt;groupId&gt;com.cenqua.clover&lt;/groupId&gt;							&lt;artifactId&gt;clover&lt;/artifactId&gt;							&lt;version&gt;3.2.0&lt;/version&gt;							&lt;scope&gt;runtime&lt;/scope&gt;						&lt;/dependency&gt;					&lt;/dependencies&gt;					&lt;executions&gt;						&lt;execution&gt;							&lt;id&gt;start-tomcat&lt;/id&gt;							&lt;phase&gt;pre-integration-test&lt;/phase&gt;							&lt;goals&gt;								&lt;goal&gt;run-war-only&lt;/goal&gt;							&lt;/goals&gt;							&lt;configuration&gt;								&lt;fork&gt;true&lt;/fork&gt;							&lt;/configuration&gt;						&lt;/execution&gt;						&lt;execution&gt;							&lt;id&gt;stop-tomcat&lt;/id&gt;							&lt;phase&gt;post-integration-test&lt;/phase&gt;							&lt;goals&gt;								&lt;goal&gt;shutdown&lt;/goal&gt;							&lt;/goals&gt;						&lt;/execution&gt;					&lt;/executions&gt;				&lt;/plugin&gt;
```

But it appears that the server does not shutdown. It will either fail on the next clean or if I set my context's antiResourceLocking to true I can see that the next time run-war-only is called I get a binding error due to the port already being in use by the previous orphaned tomcat process. Everything runs fine outside of bamboo. What do I have to configure to make this work as it should? I am using bamboo version 5.2.2 build 4010. Thanks.


Answers:
author: Sudip Pulapura
body: I too saw the same issue. The only way around this I found was to start tomcat on different ports. My problem was specifically related to clover since clover ended up running the tests twice and the second time the bind on the default port 8080 failed. I worked around this by using a plugin to allocate random ports: [](http://mojo.codehaus.org/build-helper-maven-plugin/reserve-network-port-mojo.html)<http://mojo.codehaus.org/build-helper-maven-plugin/reserve-network-port-mojo.html>and using those ports in the tomcat maven plugin.


author: Gretchen
body: When in doubt script it. If you can shut it down from the command line you can put it in a script to stop it that way. Wouldn't matter if you did it at the end of the build or as your first task in the next build.

comments: author: Joseph Cooper
body: Thanks for your reply Gretchen. The problem here is that it is an embedded instance, and I don't think a command line function will work. The shutdown method here is so far the only way I know of to shut down the embedded tomcat server. Is there another way? I haven't found anything.