General Tech Information

Auto Start Tomcat when reboot Linux PC

1. Download and install Apache Tomcat and run following command from terminal

cp $TOMCAT/bin/catalina.sh /etc/init.d/
cd /etc/init.d/
mv catalina.sh catalina

vi catalina to add/change the lines shown below

chkconfig --add catalina
chkconfig --level 2345 catalina on

 

2. reboot PC and check if tomcat start automatically

Note: This setup may not work on all linux.

 

 

Changes in file “catalina”
– Add the following lines in catalina file right after the comment lines on the top of file–
# chkconfig: - 90 15
# description: Jakarta Tomcat Java Servlets and JSP server

export CATALINA_HOME=< tomcat_path >
export JAVA_HOME=< java_path >
export PATH=$JAVA_HOME/bin:$PATH

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
}

 

– Find line # —– 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
– Find and add following lines——————————————————
elif [ "$1" = "version" ] ; then
"$_RUNJAVA" \
-classpath "$CATALINA_HOME/server/lib/catalina.jar" \
org.apache.catalina.util.ServerInfo
elif [ "$1" = "status" ];then
status
elif [ "$1" = "restart" ];then
$0 stop
$0 start
else
Yes No
Suggest Edit