Setting up Tomcat as service on Linux

Instead of manually starting Tomcat each time, you can configure it to start at boot.

1. Save tomcat start / stop script
Copy and paste the following script into your text editor:

###############################################
# This is the init script for starting up the
# Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

tomcat=/usr/local/jakarta-tomcat
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
export JAVA_HOME=/usr/local/jdk

start(){
echo -n $"Starting Tomcat service: "
#daemon -c
$startup
RETVAL=$?
echo
}

stop(){
action $"Stopping Tomcat service: " $shutdown
RETVAL=$?
echo
}

restart(){
stop
start
}


# See how we were called.
case "" in
start)
start
;;
stop)
stop
;;
status)
# This doesn't work ;)
status tomcat
;;
restart)
restart
;;
*)
echo $"Usage: @@@SMARTY:TRIM:PRE@@@ {start|stop|status|restart}"
exit 1
esac

exit 0

##############################
############ end ############


Edit the lines that start with tomcat and export to match where you installed tomcat and jdk.

I am not the original creator if this script and i got it through a friend. I modified it a little to work in my case.

2. Save to /etc/init.d and chmod

Save the edited file above to /etc/init.d directory as "tomcat" or any other name you want. Now allow execute access to the script.

3. chmod a+x tomcat

4. Add to appropriate run level directories
chkconfig --add tomcat
chkconfig tomcat on


Thats it. You might want to see which run levels you want to add this.

@man!

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments: