Ant Exec Spawn Jobs Broke Under Hudson?

Home/General/Ant Exec Spawn Jobs Broke Under Hudson?

A recent update of Hudson, a great continuous integration engine, has fixed one bug, only to introduce a new one. On February 19th, 2009, Hudson bug #2729 (an issue about Hudson not cleaning up run-away processes after the build is complete) was fixed by Hudson now killing off all processes created by the build task, including intentionally spawned daemons or tasks you wanted to keep alive.

If, like me, you use an Ant task to start your application server using an exec task with the spawn set to true at the end of a Hudson build, this means that when you upgrade Hudson, your application server will stop starting, but the rest of your build will continue to work as expected.

The issue is captured in Hudson bug #3105. The work around is to set the BUILD_ID environment variable to “dontKillMe” for the process you wish to not be killed. The Hudson bug mentions solving this through setting the BUILD_ID via a build parameter, however that requires that you enter or accept the default parameter each time you want to run the build. Instead I simply added the environment variable to my exec task, like this:

	<target name="startDynamo">
		<exec executable="${dynamo.home}/bin/startDynamo" dir="${dynamo.home}" spawn="true">
			<env key="BUILD_ID" value="dontKillMe" />
			<arg line="${dynamo.server.name}" />
		</exec>
	</target>

———-EDIT———-

You can now disable this process killing behavior globally by adding this to your JAVA_OPTS:

-Dhudson.util.ProcessTreeKiller.disable=true
By | 2017-05-18T15:16:44+00:00 March 10th, 2009|General|7 Comments

About the Author:

7 Comments

  1. Alex March 18, 2009 at 7:00 am - Reply

    Thanks. Spent about an hour troubleshooting this until I found this post.

    • Devon March 18, 2009 at 7:14 am - Reply

      Glad I could help! It took me a while to figure it out, so hopefully folks will find my page before they tear out their hair:)

  2. Suresh May 7, 2009 at 6:46 am - Reply

    great find. I’ve a similar problem when I use shell script to start my tomcat server after building the application, as soon as the job is done my tomcat stopped (or was killed rather). After spending some time I finally concluded using ant exec task is the best way to go using spawn option and I’m glad I found your article before pulling my hair out…

  3. philippe May 14, 2009 at 5:27 am - Reply

    Thanks! You saved my day, I was stuck with that odd problem!

  4. C S Shyam Sundar February 15, 2010 at 11:13 pm - Reply

    Damn! This was a life saver. :)

  5. Raivo July 18, 2010 at 7:47 am - Reply

    Thanks a lot! I would have never figured it out myself. I spent two hours debugging my server launch scripts (they worked very well with other CI tools!).

  6. […] Posted on March 10, 2009 by Devon […]

Leave A Comment