Monday, 4 July 2011

Problem with shutting down Tomcat via cargo?

I spend some time trying to fix that one, so I figured I should put it on the blog, so I won't forget about it.
We use cargo maven plugin at work to set up some container tests for our services. One of the services I checked out had a problem with it's container tests but only when they were executed via our hudson.
The error message said something like:
org.codehaus.cargo.container.ContainerException: Failed to stop the Tomcat 6.x container.

and below that:
org.codehaus.cargo.container.ContainerException:
Server port 8009 did not shutdown within the timeout period [120000]


Now I don't know much about anything as complicated as ports allocation, but I can check if something is running on a given port (thank you google). I run following command after the build failed on our hudson box:
netstat -an | grep "8009"
tcp 0 0 :::8009 :::* LISTEN

Again, don't know much about this stuff, but I'm guessing something is still running on that port. I don't own hudson box, and I don't want to break anything, so I decided to just change the tomcat AJP port for my container tests. To do that I used a cargo plugin configuration property (cargo.tomcat.ajp.port), like that:

org.codehaus.cargo
cargo-maven2-plugin


tomcat6x


file:///${basedir}/container/apache-tomcat-6.0.18.zip
${project.build.directory}/container-install-${test.container.port}



standalone
${project.build.directory}/container-config-${test.container.port}

${test.container.port}
-server -Xmx256m -Xms256m
8093

...

...



That worked pretty well, tomcat is now closing fine and the build is successful.

If you need something even more sophisticated when you start up your container, you can use ant run tasks in start and or stop goal. For more info you can check this Curiously Correct blog post.
For more info on cargo maven plugin visit cargo.codehouse.org, especially their maven plugin tips page.

6 comments:

  1. Great, thanx, that helped a lot. Running 8 Tomcats for a long time on the same machine lets you forget about the basic configuration like ajp :-(

    ReplyDelete
  2. Thanks, this helped me, too.

    ReplyDelete
  3. I had exactly the same problem (building with Hudson a project that runs Cargo)
    Thanks for the post!

    ReplyDelete
  4. Thank you, it has served me a lot.

    ReplyDelete