What might be the best way to start up tomcat instances automatically? I have numerous vhost configured to use tomcat on various ports. I am sure someone out there came across this challenging admin task. Do you think rc.local will do? I dont want to cloud that file with so many commands, I want a once off script if its applicable.
The best way under linux is with a standard SysV Init script. That is the way daemons are supposed to be started under linux so that is the first place most sys admins will look.
Standards are good like that. ;)
Many distros ship with a skeleton startup script which you can modify to suit and some ship with a library of shell functions which you can source to help you write a startup script e.g. on redhat there's
/etc/init.d/functions
.You might just use it to call the standard startup script that comes with Tomcat. Tomcat may even come with a SysV init script, I can't recall, it's been ages since I installed vanilla tomcat.
Make your startup script chkconfig-able too!
I usually use Condor for managing my 'jobs' - it allows you to distribute your app dynamically or statically if you wish. Then you should be able to use whatever auto-start mechanism you like without having your configuration floating around for everyone to see.
Why not run them all inside the same tomcat instance? Tomcat can listen on multiple ports and serve different sets of webapps from different webapp directories. Investigate the <engine> element in the tomcat's server.xml documentation.
I would recommend something like daemontools or monit. SysV or Debian initscripts are fine for starting the process on boot, but they don't automatically restart your instance if it should stop.
For
daemontools
you'll need to create arun
script that sets the user and the correct environment variables then runs$TOMCAT/bin/catalina.sh run
.For
monit
you'll need to know the location of the tomcat pid file then use a configuration similar to this:I wrote a custom init script which assumes a directory /var/tomcat contains subdirectories, each of which is the configuration for a Tomcat instance. It iterates over each subdirectory, checks whether conf/server.xml exists, and if so sets CATALINA_BASE to that subdirectory and runs its bin/catalina.sh script with the appropriate argument (stop|start).