A blog about software development, primarily in Java and about web applications.

Showing posts with label processes. Show all posts
Showing posts with label processes. Show all posts

Tuesday, March 2, 2010

Hudson v1.347 Kills Background Processes :(

I recently upgraded out Hudson instance after not touching it for quite a while. This quickly broke the set up we have in which Hudson stops and starts our Tomcat servers after a successful build to deploy the new code. The problem seems a change in the Hudson code that kills any background processes that a Hudson job leaves around. There's documentation about this issue at:

http://issues.hudson-ci.org/browse/HUDSON-2729
http://hudson.gotdns.com/wiki/display/HUDSON/Spawning+processes+from+build

We use the following shell script to stop and start Tomcat servers. The key part of the script is the setting of the environmental variable BUILD_ID=dontKillMe which overrides the default environmental variable setting Hudson gave the variable and thus prevents it from killing the background processes.


#!/bin/bash
#.Name
# startTomcat.sh
#.What
# Starts a tomcat container. This script handles some nuances of Hudson
# in which it kills background processes that you want to have stay alive
# after a build job (e.g. Restart Tomcat) finishes.
#
#.See
# http://issues.hudson-ci.org/browse/HUDSON-2729
# http://hudson.gotdns.com/wiki/display/HUDSON/Spawning+processes+from+build

exec 2>&1;

BUILD_ID=dontKillMe; export BUILD_ID;

if [ $# -ne 1 ]
then
echo "Usage: $0 full_path_to_tomcat_directory"
exit 1
fi

if [ ! -d ${1} ]
then
echo "Not a directory: ${1}"
exit 2
fi

echo $0 starting $(date)
set -x

pwd

cd $1

if [ $? -ne 0 ]
then
echo "Directory not found or has wrong permissions: $1"
exit 3
fi

pwd

./tomcat.sh stop

sleep 5

./tomcat.sh start >> ${1}/logs/start.log 2>&1

echo $0 completed $(date)

exit 0