日期:2014-05-16  浏览次数:20816 次

Linux下设置 Tomcat6开机自动启动!

?

一. 环境
1.操作系统: Suse Linux 10
2.jdk: 1.6.0_13 (使用RPM包安装)
3.jdk安装目录: /usr/java/default => /usr/java/jdk1.6.0_13
4.tomcat: tomcat6.0.20 (官方下载tgz包,直接解压到/usr/local/tomcat)
5.tomcat安装目录: /usr/local/tomcat
(一直漂[鱼漂]原创,转载请注册)

二.创建用户
#useradd -u 1003 -g users webadmin

三.修改目录所有者
#chown -R webadmin.users /usr/local/tomcat

四.安装jsvc
#cd /usr/local/tomcat/bin
#tar xvfz jsvc.tar.gz
#mv jsvc-src jsvc
#cd jsvc
#sh ./support/buildconf.sh
#chmod 755 configure
#./configure --with-java=/usr/java/default
#make
注意查看当前目录,是否生成了jsvc可执行文件.

五.修改启动文件
#vi ./native/Tomcat5.sh
改成如下内容:
(主要修改了前面的配置部分,以及start,stop中的jsvc的路径)

#!/bin/sh
#
# Startup Script for Tomcat5
#
# chkconfig: 345 87 13
# description: Tomcat Daemon
# processname: jsvc
# pidfile: /var/run/jsvc.pid
# config:
#
# Source function library.
. /etc/rc.d/init.d/functions
#
prog=tomcat
#
# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 please modify the server.xml
# file:
#
# <!-- Define a non-SSL HTTP/1.1 Connector on port 80 -->
# <Connector className="org.apache.catalina.connector.http.HttpConnector"
# port="80" minProcessors="5" maxProcessors="75"
# enableLookups="true" redirectPort="8443"
# acceptCount="10" debug="0" connectionTimeout="60000"/>
#
# You need a developement version of Tomcat (Apache Tomcat/4.1-dev)
#
# Adapt the following lines to your configuration
JAVA_HOME=/usr/local/jdk
CATALINA_HOME=/usr/local/tomcat
DAEMON_HOME=$CATALINA_HOME/bin/jsvc-src
TOMCAT_USER=tomcat
TMP_DIR=/var/tmp
CATALINA_OPTS=
CLASSPATH=$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/bin/commons-daemon.jar:$CATALINA_HOME/bin/bootstrap.jar
start(){
echo -n $"Starting $prog: "
??? #
??? # Start Tomcat
??? #
??? $DAEMON_HOME/jsvc \
??? -user $TOMCAT_USER \
??? -home $JAVA_HOME \
??? -Dcatalina.home=$CATALINA_HOME \
??? -Djava.io.tmpdir=$TMP_DIR \
??? -outfile $CATALINA_HOME/logs/catalina.out \
??? -errfile '&1' \
??? $CATALINA_OPTS \
??? -cp $CLASSPATH \
??? org.apache.catalina.startup.Bootstrap
??? #
??? # To get a verbose JVM
??? #-verbose \
??? # To get a debug of jsvc.
??? #-debug \
??? RETVAL=$?
??? [ $RETVAL = 0 ] && touch /var/lock/subsys/jsvc
??? [ $RETVAL = 0 ] && echo_success || echo_failure
??? echo
??? return $RETVAL
}
stop(){
??? echo -n $"Stopping $prog: "
??? #
??? # Stop Tomcat
??? #
??? PID=`cat /var/run/jsvc.pid`
??? kill $PID
??? RETVAL=$?
??? [ $RETVAL = 0 ] && rm /var/lock/subsys/jsvc
??? [ $RETVAL = 0 ] && echo_success || echo_failure
??? echo
??? return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo "Usage $0 start/stop"
exit 1;;
esac
??????????????????????????????????????????????


六.拷贝启动文件
#cp