If you want Tomcat to start automatically on server start, you can copy the
catalina.sh
script to your /etc/init.d directory, and with a few modifications incorporate the script into chkconfig.
mv /usr/java/tomcat/bin/catalina.sh /etc/init.d/catalina
Edit /etc/init.d/catalina then immediately following the first comments add:
# chkconfig: - 90 15
# description: Jakarta Tomcat Java Servlets and JSP server
CATALINA_HOME=/usr/java/tomcat
JAVA_HOME=/usr/java/jdkxxx
status() {
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ] ; then
echo -n "Tomcat ( pid "
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "Tomcat is stopped."
fi
}
After the line # ---- Execute the Requested Command ----
enclose the block of echo
commands within an if
condition:
# ---- Execute the Requested Command ----
if [ "$1" != "status"]; then
echo "Using CATALINA_BASE: $CATALINA_BASE"
echo "Using CATALINA_HOME: $CATALINA_HOME"
echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR"
if [ "$1" = "debug" -o "$1" = "javac" ] ; then
echo "Using JAVA_HOME: $JAVA_HOME"
else
echo "Using JRE_HOME: $JRE_HOME"
fi
fi
Before the second to last else
statement add:
elif [ "$1" = "status" ];then
status
elif [ "$1" = "restart" ];then
$0 stop
$0 start
To add /etc/init.d/catalina to chkconfig use the following commands:
chkconfig --add catalina
chkconfig catalina on