Start tomcat server

Hi,

I have s strange problem starting a tomcat server on Ubuntu

In my playbook:

  • name: Start tomcat
    action: service name=apache-tomcat-6.0.35-01 state=started

or

  • name: Start tomcat
    action: shell service apache-tomcat-6.0.35-01 start

or

  • name: Start tomcat
    action: shell /etc/init.d/apache-tomcat-6.0.35-01 start

or

  • name: Start tomcat
    action: raw /etc/init.d/apache-tomcat-6.0.35-01 start

but:

  • name: Start tomcat
    action: shell /etc/init.d/apache-tomcat-6.0.35-01 start; sleep 60

Yes, indeed it starts the server but when the playbook is finished, the daemon stops also

The daemon looks like this:

cat /etc/init.d/apache-tomcat-6.0.35-01

#!/bin/sh

Variabelen die je niet mag aanpassen!!!

VERSION=apache-tomcat-6.0.35-01
USER=tomcat
GROUP=tomcat

CATALINA_HOME=/opt/tomcat/$VERSION
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64

TOMCAT6_SECURITY=no
CATALINA_PID=/var/run/tomcat/${VERSION}.pid
CATALINA_START=“$CATALINA_HOME/bin/startup.sh”
CATALINA_STOP=“$CATALINA_HOME/bin/shutdown.sh”

export CATALINA_HOME JAVA_HOME TOMCAT6_SECURITY CATALINA_PID

Variabelen die je eventueel kunt aanpassen

-Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true : Tomcat has a memory leak where large JSP page requests can fill up memory

Currently Tomcat re-use their output buffers (ostensibly for performance), but if you serve a large amount of HTML (say 10MB) the buffers sit around forever, and don’t get cleaned up

JAVA_OPTS=“-server -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true”
MEM_PARAMS=“-Xms1024m -Xmx1024m -XX:MaxPermSize=256m -XX:PermSize=256m”
LOCAL_OPTS=“-Djava.awt.headless=true -Duser.language=nl -Duser.country=BE -Dlogging.dir=$CATALINA_HOME/logs”

Indien je een proxy nodig hebt.

JAVA_OPTS=“$JAVA_OPTS -Dhttp.proxyHost=forward-proxy-#VLAN#.mmis.be -Dhttp.proxyPort=3128 -Dhttp.nonProxyHosts=*.mmis.be|localhost”

LOCAL_OPTS=“-Djava.awt.headless=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Duser.language=nl -Duser.country=BE -Dlogging.dir=$CATALINA_HOME/logs”

Indien nodig kan je zelf bijkomende environment variabelen plaatsen in:

$CATALINA_HOME/bin/setenv.sh

Zet de rechten goed: chmod 755 $CATALINA_HOME/bin/setenv.sh

. /lib/lsb/init-functions

if [ ! -d /var/run/tomcat ]; then
mkdir -p /var/run/tomcat
chown $USER:$GROUP /var/run/tomcat
fi

case $1 in
‘start’)
JAVA_OPTS=“$JAVA_OPTS $MEM_PARAMS $LOCAL_OPTS”; export JAVA_OPTS
touch $CATALINA_PID
chown $USER:$GROUP $CATALINA_PID
/sbin/start-stop-daemon -S -u $USER -g $GROUP -c $USER -x $CATALINA_START
;;
‘stop’)
JAVA_OPTS=“-Dlogging.dir=$CATALINA_HOME/logs”; export JAVA_OPTS

Indien je -u $USER meegeeft dan gaat hij ook andere tomcat daemons stoppen

/sbin/start-stop-daemon -K -p $CATALINA_PID -R TERM/20/KILL/5
rm -f $CATALINA_PID
;;

‘restart’)
$0 stop
sleep 10
$0 start
;;
*)
echo “Usage: $0 { start | stop | restart }”
exit 1
;;
esac
exit 0

No problem when starting the deamon on the server.
Any ideas?

Regards,
Gerrit

Out of curiosity, is there any reason you are running a custom tomcat6
instead of using the one from apt? Your init script seems odd. Are
you missing the

   --pidfile "$CATALINA_PID"

section for the start-stop-daemon parameters, or

   >/dev/null;

at the end of the same line?

How does the init script behave when run it from the command-line?

I ran in to a similar problem here at work with some in-house Java apps.

Let me preface this by mention that I'm a seasoned developer that has been picking up system admin knowledge as I go. I'm sure there are many peopl eon here with more extensive knowledge of what's going on here.

setsid /bin/sh -i -c "/apps/path/scripts/run -start" &> /tmp/null

This lauches a shell process as its own process group independant of the script launching it and run the init script. The pipe all to null is crucial otherwise the shell blocks waiting to receive something.

Hope that helps.

<tim/>

Hi,

I found the problem. It is indeed a problem with the child process.

I changed:

/sbin/start-stop-daemon -S -u $USER -g $GROUP -c $USER -x $CATALINA_START
into:
/sbin/start-stop-daemon -S -b -u $USER -g $GROUP -c $USER -x $CATALINA_START

-b option fixed this:

**-b , -background**
Force the daemon into the background. Some daemons don't create pidfiles, so a good trick is to get the daemon to run in the foreground, and use the this option along with -**m , -make-pidfile** to create a working pidfile.

We make are own tomcat packages, we never do an upgrade. All versions are deployed in the folder:
ex.: apache-tomcat-6.0.32-03.deb apache-tomcat-6.0.35-01.deb (The last 2 figures is our version)

and are deployed in

/opt/tomcat/apache-tomcat-6.0.32-03
/opt/tomcat/apache-tomcat-6.0.35-01

Regards,
Gerrit