操作系统 > RedHat/Centos >
CentOS Tomcat 的启动服务脚本
脚本之家
1. tomcat 自带的 jsvc, 这个工具会启动2个线程,如果应用对资源独占,会造成应用启动不了,这个和Apache Commons 里的 daemon 项目是一样的。
2. Java Service Wrapper ,
参考nginx的脚本,自己写了一个脚本,供大家参考:
#
#!/bin/bash
#
# chkconfig: - 91 35
# description: Starts and stops tomcat
CATALINA_HOME=/data/site/tomcat-8085
PID_FILE=/var/run/tomcat8085.pid
JAVA_HOME=/usr/java/default
JAVA_OPTS="-server -Xms512m -Xmx1024m"
CATALINA_BASE=$CATALINA_HOME
CATALINA_OPTS="-Djava.library.path=$CATALINA_HOME/bin"
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar
RETVAL=0
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# Start daemons functions.
start() {
#
# Start Tomcat
#
if [ -e $PID_FILE ];then
echo "$PID_FILE already running...."
exit 1
fi
echo -n $"Starting $PID_FILE: "
nohup $JAVA_HOME/bin/java \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
$CATALINA_OPTS \
-cp $CLASSPATH \
$JAVA_OPTS \
org.apache.catalina.startup.Bootstrap start >$CATALINA_HOME/logs/catalina.out &
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $PID_FILE
return $RETVAL
}
# Stop daemons functions.
stop() {
#
# Stop Tomcat
#
echo -n $"Stopping $PID_FILE: "
nohup $JAVA_HOME/bin/java \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap stop >$CATALINA_HOME/logs/catalina.out &
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $PID_FILE
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
exit 1
esac
exit $RETVAL
安装步骤
1. #vi tomcatd 输入以上脚本
2. #chmod +x tomcatd 设置有执行权限
3. #cp tomcatd /etc/init.d 复制到启动目录
4. #chkconfig --add tomcatd
5. #chkconfig tomcatd on
6. #service tomcatd start 启动
7. #service tomcatd stop 停止
2. Java Service Wrapper ,
参考nginx的脚本,自己写了一个脚本,供大家参考:
#
#!/bin/bash
#
# chkconfig: - 91 35
# description: Starts and stops tomcat
CATALINA_HOME=/data/site/tomcat-8085
PID_FILE=/var/run/tomcat8085.pid
JAVA_HOME=/usr/java/default
JAVA_OPTS="-server -Xms512m -Xmx1024m"
CATALINA_BASE=$CATALINA_HOME
CATALINA_OPTS="-Djava.library.path=$CATALINA_HOME/bin"
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar
RETVAL=0
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# Start daemons functions.
start() {
#
# Start Tomcat
#
if [ -e $PID_FILE ];then
echo "$PID_FILE already running...."
exit 1
fi
echo -n $"Starting $PID_FILE: "
nohup $JAVA_HOME/bin/java \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
$CATALINA_OPTS \
-cp $CLASSPATH \
$JAVA_OPTS \
org.apache.catalina.startup.Bootstrap start >$CATALINA_HOME/logs/catalina.out &
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $PID_FILE
return $RETVAL
}
# Stop daemons functions.
stop() {
#
# Stop Tomcat
#
echo -n $"Stopping $PID_FILE: "
nohup $JAVA_HOME/bin/java \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap stop >$CATALINA_HOME/logs/catalina.out &
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $PID_FILE
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
exit 1
esac
exit $RETVAL
安装步骤
1. #vi tomcatd 输入以上脚本
2. #chmod +x tomcatd 设置有执行权限
3. #cp tomcatd /etc/init.d 复制到启动目录
4. #chkconfig --add tomcatd
5. #chkconfig tomcatd on
6. #service tomcatd start 启动
7. #service tomcatd stop 停止