#!/bin/sh
#
# Wrapper for running Tomcat under launchd
# Required because launchd needs a non-daemonizing process

function shutdown()
{
        $CATALINA_HOME/bin/shutdown.sh
	/bin/rm $CATALINA_PID
}

function wait_for_death()
{
	while /bin/kill -0 $1 2> /dev/null ; do
		sleep 2	
	done
}

export CATALINA_PID=$CATALINA_HOME/logs/tomcat.pid
$CATALINA_HOME/bin/startup.sh
trap shutdown QUIT ABRT KILL ALRM TERM TSTP
sleep 2
wait_for_death `cat $CATALINA_PID`
