1

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.

5 Answers 5

2

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!

2
  • Yes there is a tomcat SysV init script, well this one is starting some instances but not all. Some tomcat instances are sitting in different dir, where tomcat init script in not pointing at. I can't say whay this was done,I inherited the servers. Some info that I might have left out; there is also a tomcat instance that was installed from source and some vhosts are pointing to that one. I reckon that rc.local will be an easy way out while I do sane :)
    – Rungano
    Jun 23, 2009 at 6:09
  • Then copy the existing tomcat startup script and edit it to point at the other instances. Or create new tomcat startup scripts and put the commands you were going to put into rc.local in them. Init scripts are the right way to go and you don't lose anything by using them. It makes it easier for the next guy who takes a look at the box.
    – Jason Tan
    Jun 23, 2009 at 15:16
0

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.

0

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.

0

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 a run 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:

check process 'tomcat' with pidfile /path/to/your/tomcat/tmp/tomcat.pid
   start command = '$TOMCAT/bin/catalina.sh start'
   stop  command = '$TOMCAT/bin/catalina.sh stop' 
1
  • I have nagios to monitor the web pages so I will be notified via sms that a certain web page is not loading properly. Thank you big time for broading my options. :)
    – Rungano
    Jun 24, 2009 at 6:43
0

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).

1
  • Can you paste that script here?
    – Rungano
    Aug 7, 2009 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .