Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Apache Tomcat Upstart script
description "Tomcat Server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
# run as non privileged user
# add user with this command:
## adduser --system --ingroup www-data --home /opt/apache-tomcat apache-tomcat
# Ubuntu 12.04: (use 'exec sudo -u apache-tomcat' when using 10.04)
setuid apache-tomcat
setgid www-data
# adapt paths:
env JAVA_HOME=/opt/java
env CATALINA_HOME=/opt/apache-tomcat
# adapt java options to suit your needs:
env JAVA_OPTS="-Djava.awt.headless=true -Xms512M -Xmx1024M -server -XX:+UseParallelGC"
exec $CATALINA_HOME/bin/catalina.sh run
# cleanup temp directory after stop
post-stop script
rm -rf $CATALINA_HOME/temp/*
end script
@witscher

This comment has been minimized.

Copy link
Owner Author

commented Jun 13, 2012

works for both tomcat 6 and tomcat 7, tested on Ubuntu 10.04 x64

@witscher

This comment has been minimized.

Copy link
Owner Author

commented Oct 11, 2012

now optimized for Ubuntu 12.04

@bryanwb

This comment has been minimized.

Copy link

commented Mar 22, 2013

@witscher How do you redirect stdout and stderr for catalina.sh to a log file like catalina.out?

@minzie31

This comment has been minimized.

Copy link

commented Apr 22, 2013

Don't you need an expect stanza? What happens when you do a initctl status tomcat?

@witscher

This comment has been minimized.

Copy link
Owner Author

commented Aug 2, 2013

expect is not needed, status displays like this:

tomcat start/running, process

@witscher

This comment has been minimized.

Copy link
Owner Author

commented Aug 2, 2013

@brianwb Since newer upstart versions (12.04) stdout and stderr go into /var/log/upstart/tomcat.log, so theres no need to catch it in the script

@alanfranz

This comment has been minimized.

Copy link

commented Oct 9, 2013

you should use CATALINA_OPTS for heap/server/gc settings; java_opts is passed even when other commands are issued on the 8005 port, even though this is unused by this config file.

See my fork for an example:

https://gist.github.com/alanfranz/6902429

@gdbtek

This comment has been minimized.

Copy link

commented Mar 29, 2014

hi all,

when I set:
setuid tomcat setgid www-data

start tomcat can't boot up tomcat. My tomcat only can boot up when I remove above setuid and setgid. I added tomcat user to www-data as you can see:

groups tomcat

tomcat : www-data

does anyone know what seem to be wrong?

Thanks

@gdbtek

This comment has been minimized.

Copy link

commented Mar 29, 2014

never mind, I got it! Thanks

@clement-bramy

This comment has been minimized.

Copy link

commented Apr 8, 2014

Hello,

Did you try it with tomcat 8?
Can you see any reason why it would not work?

Clem

@robertandrewbain

This comment has been minimized.

Copy link

commented Jan 5, 2015

Confirmed working with tomcat 8.

@EzenwakaKaycee

This comment has been minimized.

Copy link

commented Aug 6, 2015

Pls How do i run the tomcat as root user

@vancluever

This comment has been minimized.

Copy link

commented Nov 2, 2015

Thank you so much for this dude, and for anyone reading this, the key to this is the run parameter versus the start parameter. I'd imagine that the latter causes it to fork in a way that breaks upstart (well documented).

Stumbling upon this saved my eyeballs a pending gouging. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.