redhat as 4 下tomcat的autostart(转)

来源:互联网 发布:曹县大集淘宝村地图 编辑:程序博客网 时间:2024/06/05 16:31
忙了好长一段时间,网上也有好多的解决方法,但是我试过,一个都不行,至少我不行,最后终于找到一个方法成功的,现在介绍给大家.
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
 
原创粉丝点击