jonm.dev

The Art of Writing Software



Keep It Simple, Stupid

Tags [ Cargo, curl, Maven, Maven2, shell script, Tomcat ]

Well, I just spent a couple of hours last night trying to get the Cargo Maven2 plugin to work the way I wanted it to, which was to be able to control an already-installed local Tomcat by saying mvn cargo:start and then having that process exit.

Now the whole motivation was to try to get CruiseControl to redeploy the latest version of our webapp after a successful build. Due to various undeploy/deploy cycle PermGen memory leaks, and because it’s on a shared server, I essentially wanted to just have CC do a mvn cargo:undeploy cargo:stop cargo:deploy cargo:start. Unfortunately, it looked like this process would hang.

When I took a step back, I realized I could do that with a pretty short shell script, something like:

#!/bin/sh

# ... config variables here

curl --user $TOMCAT_ADMIN:$TOMCAT_PASSWD --url http://localhost:$TOMCAT_PORT/manager/html/undeploy?path=/
(cd $CATALINA_HOME; bin/shutdown.sh)
scp $MAVEN_REPO/webapp-1.2.3-SNAPSHOT.war $CATALINA_HOME/webapps/ROOT.war
(cd $CATALINA_HOME; bin/startup.sh)

Ok, a little more error checking, and you’re basically done, and then just use an <exec> CC task conditionally off the normal continuous integration task.

Moral of the story: don’t try too hard to do things in a fancy, snazzy way when a simple way works just fine. Incidentally, this is why some of my favorite phone screen questions to ask folks who are interviewing are (more or less): * what programming languages do you know/use? * do you know your way around a Unix command prompt?

If I didn’t know enough Unix commands or shell scripting to do what I did above, I probably would have either given up or had to spend a ton more hours digging through the source code to the maven plugin to figure out why it wasn’t doing what I wanted it to do.