Is there a proper way to run more than one tomcat instance on an Ubuntu server?
I've done some searching and found two options:
- Download a zipped tomcat and manually deploy it. The obvious con is that it won't be upgraded using
apt-get
. - Use some advanced scripting, which is dangerous in a production server.
Any other ideas to cleanly run another instance?
Thanks in advance,
Adam
Have you considered configuring several webapps directories instead of running multiple tomcat instances?
Of course there are cases where you really need multiple instances but in case of serving same application separately for multiple hosts, you may do it by adding multiple declarations in server.xml:
Now you may create "/var/lib/tomcat6/host1" and "/var/lib/tomcat6/host2" directories and deploy WAR files to them.
I am setting this up on Ubuntu 14.04.3 LTS. I am using the Tomcat 7 provided by the
tomcat7
package.It installs Tomcat as a system service by providing a standard init script:
and configuration file:
Tomcat supports running multiple instances with the same server software. The server software is located in
$CATALINA_HOME
, the files for the instance are located in$CATALINA_BASE
. They are defined as follows in/etc/init.d/tomcat7
:(Caveat: when editing files in the latter, be aware that it has some symlinks into the former.)
The
tomcat7-user
package provides the utilitytomcat7-instance-create
that can be used to create a directory tree for an additional Tomcat instance, including abin/
directory with scripts for starting and stopping the instance manually.What I haven't found is support for turning such an additional instance into a system service. Therefore, it must be done manually, e.g. as follows:
$NAME
in the new init script.tomcat7
user.tomcat7-instance-create
as that user to create a Tomcat instance.bin/startup.sh
andbin/shutdown.sh
scripts./var/log/$NAME
and symlink them back tologs/
of the new Tomcat instance./etc/init.d/$NAME
, e.g. by copying and modifying/etc/init.d/tomcat7
and modifying the assignment to$NAME
. (It would be nicer if you didn't need to copy the whole script but could just create a link to it.)/etc/default/$NAME
to point at your Tomcat instance and user.upstart-rc.d
to install the new service.I gleaned some of the details from Kodjo-Kuma Djomeda.
I did the following:
run the following command with the dir where tomcat should be created:
than changed the ports to something unique (if you have other tomcat8 running:
i use the same user as the original tomcat8 so i make sure all files are owned by tomcat8
i copied the script tomcat8 script in /etc/init.d/
and edited the script to make it work with my new staging env:
i had to edit the following lines to:
and finally i enabled the server like this:
when starting it with:
i got an error about missing policy files so i created a link for that in the conf dir: