Packaging webapps for deployment in Tomcat 6.0 in Debian and Ubuntu

Option 1: Use the system instance

The tomcat6 package provides a system-wide instance. If your webapp is relatively simple and does not require a specific configuration, you should consider packaging your webapp for deployment there. That’s what the tomcat6-examples and tomcat6-admin packages do. To benefit from webapp autodeployment, you should:

Option 2: Use your own instance

Sometimes using the system-wide Tomcat 6.0 instance is just not the right solution. The most common case is when your webapp requires a very specific configuration. Rather than beating the system-wide instance into submission, by mangling the configuration file (or asking your users to do so), it’s better to set up your own instance. Tomcat 6.0 in Ubuntu and Debian provides the possibility to set up multiple instances of tomcat that share the same binaries, through the tomcat6-common package. You should then:

Depend on the tomcat6-common package

Deploy a full CATALINA_BASE directory with conf/ and webapp/ subdirectories in /usr/share/PACKNAME

Create an init script in /etc/init.d/PACKNAME that starts catalina.sh with CATALINA_BASE=/usr/share/PACKNAME and CATALINA_HOME=/usr/share/tomcat6

Have postinst create a specific user to run under, and use that in your init script

Create specific directories for logs and temporary files

What should the CATALINA_BASE directory look like ? Something like this:

It is slightly more complex, but that way you can fine-tune your configuration without affecting any other webapp installed, since you use your own, separate, instance. Most importantly, you still get the benefit of bugfix and security updates in the common binaries.

If you need some examples, the tomcat6-user package provides a tomcat6-create-instance command that creates CATALINA_BASE directories for user instances, you can use that as a base. For the init script, /etc/init.d/tomcat6 can be used as a base.