最近离职,在找工作之余看了一下tomcat,顺便分享一个tomcat的启动脚本.
该脚本来源于tomcat自带的catalina.sh,具体内容如下,想必大家都一目了然
#!/bin/bash
#chkconfig: 2345 96 14
#导出java环境变量
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64
#导出tomcat环境变量
export CATLINA_PATH=/usr/local/tomcat
#启动时tomcat的进程号
TOMCAT_PID=`/usr/bin/jps | grep Bootstrap | awk '{print $1}'`
#查看tomcat状态
if [ "$*" == 'status' ]; then
# TOMCAT_PID=`/usr/bin/jps | grep Bootstrap | awk '{print $1}'`
if [ "$TOMCAT_PID" == "" ]; then
if [ -n "$TOMCAT_PID" ]; then
echo "tomcat is running(pid:$TOMCAT_PID)."
else
echo "tomcat is not running."
fi
#重启tomcat
elif [ "$*" == "restart" ]; then
if [ "$TOMCAT_PID" != "" ]; then
kill -9 $TOMCAT_PID
sleep 1
fi
exec $CATLINA_PATH/bin/catalina.sh start
else
exec $CATLINA_PATH/bin/catalina.sh $*
fi
最后将脚本添加为系统服务,利用service启动
cp tomcat /etc/init.d/tomcat
chkconfig --add tomcat