Debian Linux : how to autostart tomcat on bootup

hello experts

i have manually installed tomcat server 5 at /usr/local/tomcat
on a ubuntu machine and another debinac machine
i  want to start tomcat server automatically on reboot of the machine

i googled but the help is for tomcat 4 versions where TOMCAT_HOME variable is used
now in my server CATALINA_HOME is used
so i'm confused
pls provide the script for tomcat 5 server

pls guide
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

your tomcat should come with a sample rc-script
copy this script to the proper rc-directory (/etc/init.d/ usually) then enable the startup with the proper tools (IIRC it is sysconfig on RH)
EconifyAuthor Commented:
hi hoff man
no idea bat what u r saying

copy this script to the proper rc-directory (/etc/init.d/ usually) then enable the startup with the proper tools (IIRC it is sysconfig on RH)

can u pls elaborate on this
rc-scripts are scripts used by Unix/linux while booting. Each script must have at least 2 modes: start and stop.
These "modes" are passed as parameter to the script.
If tomcat does not come with such a script, use the sample one you find in /etc/init.d and adapt it for tomcat, giv it a unique name and enable it with the proper RH tool (sysconfig).
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Attached the script i use to start tomcat5 on bootup

1) create a system user tomcat5 (useradd or adduser)
2) change script paramater (leave CATALINA_BASE is unnesecairy)
3) copy script to /etc/init.d/tomcat5
4) use update-rc.d(or rc.d-update ;)) to create the symlinks :
 update-rc.d tomcat5 defaults 90

#! /bin/sh
# skeleton      Example initscript
#            This file should be used to construct scripts to be
#            placed in /etc/init.d.
# Author:      Miquel van Smoorenburg <>.
#            Ian Murdock <>.
#            Please remove the "Author" lines above and replace them
#            with your own name if you copy and modify this script.
# Version:      @(#)skeleton  2.85-23  28-Jul-2004

set -e

DESC="servlet container"


# Gracefully exit if the package has been removed.
test \( -x $DAEMON_START -a -x $DAEMON_STOP -a -x  $DAEMON_CONTROL \)  || exit 0

# Read config file if it is present.
#if [ -r /etc/default/$NAME ]
#      . /etc/default/$NAME

#      Function that starts the daemon/service.
d_start() {
      #start-stop-daemon --start --quiet --pidfile $PIDFILE \
      #      --exec $DAEMON
      su - $TOMCAT_USER -s /bin/bash -c "$DAEMON_START"

#      Function that stops the daemon/service.
d_stop() {
      #start-stop-daemon --stop --quiet --pidfile $PIDFILE \
      #      --name $NAME
      su - $TOMCAT_USER -s /bin/bash -c "$DAEMON_STOP"

#      Function that sends a SIGHUP to the daemon/service.
d_debug() {
      #start-stop-daemon --stop --quiet --pidfile $PIDFILE \
      #      --name $NAME --signal 1
      su - $TOMCAT_USER -s /bin/bash -c "$DAEMON_CONTROL run"

case "$1" in
      echo -n "Starting $DESC: $NAME"
      echo "."
      echo -n "Stopping $DESC: $NAME"
      echo "."
      echo -n "starting $DESC in debug mode: $NAME"
      echo "done."
      echo -n "Restarting $DESC: $NAME"
      sleep 1
      echo "."
      # echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
      echo "Usage: $SCRIPTNAME {start|stop|restart|debug}" >&2
      exit 1

exit 0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
you might also do a chown tomcat5 -R <CATALINA_HOME> to make sure tomcat can read everything
su in an rc-script, is tomcat that stupid?
also, if su is really necessary, I'd use it without - 'cause the shell profiles may contain dangerous things (like stty, etc.)
su in an rc-script, is tomcat that stupid?
euhm, java doesn't know how todrop privelegdes and you don't want tomcat to run as root.

the '-' allows me to specify the custom path variable (exclude binaries/specify alternative JVM/....) and if someone is able to add content to the .profile you have bigger problems to worry about.
EconifyAuthor Commented:
hi verborghs
u script is absolutely amazing
hey other guys this is way to answer(please guys be a little elaborate)

thanks a ton for that

can u explain me what is

update-rc.d tomcat5 defaults 90

and will this script shutdown the server properly in case there is a halt or reboot

thanks again
> .. java doesn't know how todrop privelegdes ..
LOL, another reason to switch back to reliable shell scripting ;-)

> .. you have bigger problems to worry about.
agreed, my intent was to point to these problems.
update-rc.d makes links from the needed rcX.d folders. the folders control what gets starten in which runlevel. runlevels are like safe-boot/networking/no-networking/normal choice you have when booting windows only better ;)

because of the names of the links that get created your linux system will call the script with start or stop as an argument, so yes, your tomcat will be shutdown as it shoul
EconifyAuthor Commented:
hi verborghs

there's a small error in ur script
su - $TOMCAT_USER -s /bin/bash -c "$DAEMON_CONTROL run"
shud be
su - $TOMCAT_USER -s /bin/bash -c "$DAEMON_CONTROL" run
other wise u get the error not a directory

and hey i just did a shutdown -r now
and the tomcat did not start automaticaly on bootup
EconifyAuthor Commented:
i checked whether the link is there
and its there
debinac:~# update-rc.d tomcatstartnew defaults 90
 System startup links for /etc/init.d/tomcatstartnew already exist.
whats 90 for ??
> and the tomcat did not start automaticaly on bootup
check your error logs of tomcat

> whats 90 for ??
it's a number used in the name of the link created by update-rc.d, if you look in the /etc/rc.d/rc3.d/ directory you'll see that all scripts are named SNNname and/or KNNname where NN is such a number. While booting scripts are started in sequence of these numbers, same applies for shutdown.
EconifyAuthor Commented:
thanks dudes
now it works
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.