# Start tomcat server

**URL:** <https://forum.ansible.com/t/start-tomcat-server/11860>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [September 4, 2012, 2:42pm UTC](https://forum.ansible.com/t/start-tomcat-server/11860 "2012-09-04T14:42:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yerrysherry](https://avatars.discourse-cdn.com/v4/letter/y/b5e925/32.png) [@yerrysherry](https://forum.ansible.com/u/yerrysherry)\
**Post date:** [September 4, 2012, 2:42pm UTC](https://forum.ansible.com/t/start-tomcat-server/11860/1 "2012-09-04T14:42:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CWS](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@CWS](https://forum.ansible.com/u/CWS)\
**Post date:** [September 4, 2012, 2:52pm UTC](https://forum.ansible.com/t/start-tomcat-server/11860/2 "2012-09-04T14:52:18Z")

</div>

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

&nbsp;&nbsp;&nbsp;--pidfile "$CATALINA\_PID"

section for the start-stop-daemon parameters, or

&nbsp;&nbsp;&nbsp;\>/dev/null;

at the end of the same line?

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

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [September 4, 2012, 3:28pm UTC](https://forum.ansible.com/t/start-tomcat-server/11860/3 "2012-09-04T15:28:13Z")

</div>

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/\>

---

<div class="post-metadata">

**Author:** ![yerrysherry](https://avatars.discourse-cdn.com/v4/letter/y/b5e925/32.png) [@yerrysherry](https://forum.ansible.com/u/yerrysherry)\
**Post date:** [September 5, 2012, 1:51pm UTC](https://forum.ansible.com/t/start-tomcat-server/11860/4 "2012-09-05T13:51:22Z")

</div>

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
