今天在Linux上装了一个Tomcat,发现它自带的那个jsvc启动脚本实在太古老了。于是就在网上Search了一下,加上自己修改code。写了一个适合于tomcat6用的jsvc启动脚本。使用以后就可以把tomcat做为linux的Service来自启动了。
把这段代码保存为 /etc/rc.d/init.d/tomcat ,然后运行
#chkconfig –add tomcat
用–list看一下是否系统已有tomcat启动文件
#ckhconfig –list
即可把tomcat 添加为系统服务自动随系统启动了。这个脚本会在runlevel 3/4/5三种模式自动启动。
代码
- #!/bin/sh
- ##############################################################################
- #
- # Copyright 2004 The Apache Software Foundation.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ##############################################################################
- #
- # 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"/>
- #
- # That is for Tomcat-5.0.x (Apache Tomcat/5.0)
- #
- # chkconfig: 345 87 13
- # description: Tomcat Daemon
- # processname: jsvc
- # pidfile: /var/run/jsvc.pid
- # config:
- #
- # Source function library
- . /etc/rc.d/init.d/functions
- #
- # Adapt the following lines to your configuration
- JAVA_HOME=/usr/java/default
- CATALINA_HOME=/opt/apache-tomcat
- DAEMON_HOME=/opt/apache-tomcat
- TOMCAT_USER=root
- # for multi instances adapt those lines.
- TMP_DIR=/var/tmp
- PID_FILE=/var/run/jsvc.pid
- CATALINA_BASE=/opt/apache-tomcat
- CATALINA_OPTS="-Djava.library.path=/home/jfclere/jakarta-tomcat-connectors/jni/native/.libs"
- CLASSPATH=
- $JAVA_HOME/lib/tools.jar:
- $CATALINA_HOME/bin/commons-daemon.jar:
- $CATALINA_HOME/bin/bootstrap.jar
- prog="tomcat"
- start(){
- #
- # Start Tomcat
- #
- echo -n $"Starting $prog:"
- $DAEMON_HOME/bin/jsvc
- -user $TOMCAT_USER
- -home $JAVA_HOME
- -Dcatalina.home=$CATALINA_HOME
- -Dcatalina.base=$CATALINA_BASE
- -Djava.io.tmpdir=$TMP_DIR
- -wait 10
- -pidfile $PID_FILE
- -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(){
- #
- # Stop Tomcat
- #
- echo -n $"Stopping $prog: "
- $DAEMON_HOME/bin/jsvc
- -stop
- -pidfile $PID_FILE
- org.apache.catalina.startup.Bootstrap
- 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
- ;;
- status)
- status jsvc
- RETVAL=$?
- ;;
- *)
- echo "Usage %0 start/stop/restart"
- exit 1;;
- esac
LX同学就是一天整些专业文章~