设置linux自动启动和关闭tomcat

使用系统版本:Redhat6-64

方法1、修改/etc/rc.local文件,自动启动tomcat

export JAVA_HOME=/usr/local/jdk1.6.0_27
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export JAVA_OPTS="-Xms1800m -Xmx2000m -Xmn600m -XX:PermSize=128m -XX:MaxPermSize=512m  -Xloggc:/usr/local/apache-tomcat-7.0.32_hfd_cxjc/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps"


alias startbg='nohup /usr/local/apache-tomcat-7.0.32_hfd_cxjc/bin/catalina.sh run > /usr/local/log.out &'
alias stoptomcat='/usr/local/apache-tomcat-7.0.32_hfd_cxjc/bin/shutdown.sh'
alias showlog='tail -n 30 -f /usr/local/log.out'

starbg


方法2、把tomcat设置为服务,可随系统自动启动和关闭


step1. vi /etc/rc.d/init.d/tomcat,详见文件尾部。

step2. chkconfig --add tomcat

step3. 检查是否可以调用service tomcat start 和stop

step4.reboot 验证



vi /etc/rc.d/init.d/tomcat的文件内容:

#!/bin/bash
#
#Startup script for the tomcat
#
# chkconfig: 345 80 15
# description: Tomcat is a Servlet+JSP Engine.
 
# Source function library.
. /etc/rc.d/init.d/functions
 
JAVA_HOME=/usr/local/jdk1.6.0_27
 
CATALINA_HOME=/usr/local/apache-tomcat-7.0.32_hfd_cxjc


TOMCAT_HOME=/usr/local/apache-tomcat-7.0.32_hfd_cxjc
 
export JAVA_HOME CATALINA_HOME TOMCAT_HOME
 
 
start(){
#if [ -z $(/sbin/pidof java) ]; then
echo "Starting tomcat"
$TOMCAT_HOME/bin/startup.sh
touch /var/lock/subsys/tomcat
#else
#echo "tomcat allready running"
#fi
}
 
stop(){
#if [ ! -z $(/sbin/pidof java) ]; then
echo "Shutting down tomcat"
$TOMCAT_HOME/bin/shutdown.sh
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)
$TOMCAT_HOME/bin/catalina.sh version
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
 
exit 0
 

你可能感兴趣的:(linux,tomcat,tomcat,autostart,自动启动,linux)