Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

5 Answers 5

up vote 2 down vote accepted

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!

share|improve this answer
    
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 '09 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 '09 at 15:16
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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'
share|improve this answer
    
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 '09 at 6:43
add comment

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

share|improve this answer
    
Can you paste that script here? –  Rungano Aug 7 '09 at 14:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.