linux环境下配置Tomcat自启动

[root@sample ~]# vi /etc/rc.d/init.d/tomcat  ← 建立Tomcat启动脚本,如下:


#!/bin/bash
#
# Startup script for the tomcat
#
# chkconfig: 345 80 15
# description: Tomcat is a Servlet+JSP Engine.

export JAVA_HOME=/usr/java/jdk1.6.0_06        注:指定JDK 安装目录路径
export JAVA_JRE=/usr/java/jdk1.6.0_06/jre     注:指定JRE 安装目录路径

# Source function library.
. /etc/rc.d/init.d/functions

start(){
if [ -z $(/sbin/pidof java) ]; then
echo "Starting tomcat"
/usr/apache-tomcat-6.0.30/bin/startup.sh     注:指定TOMCAT 安装目录路径
touch /var/lock/subsys/tomcat
else
echo "tomcat allready running"
fi
}

stop(){
if [ ! -z $(/sbin/pidof java) ]; then
echo "Shutting down tomcat"
/usr/apache-tomcat-6.0.30/bin/shutdown.sh     注:指定TOMCAT 安装目录路径
until [ -z $(/sbin/pidof java) ]; do :; done
rm -f /var/lock/subsys/tomcat
else
echo "tomcat not running"
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
/usr/apache-tomcat-6.0.30/bin/catalina.sh version   注:指定TOMCAT 安装目录路径
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
exit 0



[root@sample ~]# chmod 755 /etc/rc.d/init.d/tomcat  ← 将启动脚本属性设置为755(使之可执行)

[root@sample ~]# chkconfig --add tomcat  ← 将Tomcat加入到chkconfig中

[root@sample ~]# chkconfig tomcat on   ← 将Tomcat设置为自启动

[root@sample ~]# chkconfig --list tomcat  ← 确认Tomcat服务状态
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off  ← 确认2~5为on的状态就OK

[root@sample ~]# /etc/rc.d/init.d/tomcat restart  ← 重启动Tomcat测试


你可能感兴趣的:(tomcat,脚本)