Below set of steps involve setting up Tomcat 6 on CentOS 5 with Java 1.6
Download Apache Tomcat
$ wget http://apache.parentingamerica.com/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.tar.gz
Go to opt/ folder and extract Tomcat
$ cd /opt
$ tar -xzf apache-tomcat-6.0.36.tar.gz
Create a tomcat user
$ useradd -d /opt/apache-tomcat-6.0.36/ tomcatuser
Change user permission on tomcat folder
$ chown -R tomcatuser:tomcatuser apache-tomcat-6.0.36
$ vi /etc/init.d/tomcat
#!/bin/bash
#
# tomcat Starts Tomcat Java server.
#
#
# chkconfig: 345 88 12
# description: Tomcat is the server for
# Java servlet applications.
### BEGIN INIT INFO
# Provides: $tomcat
### END INIT INFO
JAVA_HOME=/usr/java/jdk1.6.0_37
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
TOMCAT_HOME=/opt/apache-tomcat-6.0.36/bin
START_TOMCAT=/opt/apache-tomcat-6.0.36/bin/startup.sh
STOP_TOMCAT=/opt/apache-tomcat-6.0.36/bin/shutdown.sh
# Source function library.
. /etc/init.d/functions
[ -f $START_TOMCAT ] || exit 0
[ -f $STOP_TOMCAT ] || exit 0
RETVAL=0
umask 077
start() {
echo -n $"Starting Tomcat Java server: "
daemon su -c $START_TOMCAT tomcatuser
echo
return $RETVAL
}
stop() {
echo -n $"Shutting down Tomcat Java server: "
daemon su -c $STOP_TOMCAT tomcatuser
echo
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
Now save the file
Give executable rights for that script
$ chmod 755 /etc/init.d/tomcat
Add the script to CentOS services
$ chkconfig –add tomcat
Check the changes
$ chkconfig –level 234 tomcat on
$ chkconfig –list tomcat
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Test that the script is working and it gives no errors
$ service tomcat start
$ service tomcat restart
$ service tomcat stop