前言:
在设定好Tomcat后,大多数人都会希望开机后自动启动。但是如果把启动路径加到/etc/rc.d/rc.local是不会生效的。因此必须在做一些设定。其实设定的方式有很多种,在这边介绍设定为Service的方式。然后在设定开机启动这样就可以了。
设定Tomcat开机启动
设定启动脚本
以下加入的内容,路径的部份请依个人tomcat安装路径设定。
[root@localhost ~]# cd /etc/init.d
[root@localhost ~]# vim tomcat
#加入以下内容
tartup script for jakarta tomcat
chkconfig: - 85 20
description: Tomcat running
processname: tomcat6
pidfile: /var/run/tomcat.pid # config:# Source function library.
. /etc/rc.d/init.d/functions
Source networking configuration.
. /etc/sysconfig/network
Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0# Set Tomcat environment.
export JAVA_HOME=/usr/java/jdk
export CATALINA_HOME=/opt/apache-tomcat-6.0.33
export CATALINA_OPTS="-Dbuild.compiler.emacs=true"
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar
export PATH=$JAVA_HOME/bin:$PATH
[ -f /opt/apache-tomcat-6.0.33/bin/startup.sh ] || exit 0 [ -f /opt/apache-tomcat-6.0.33/bin/shutdown.sh ] || exit 0
export PATH=$PATH:/usr/bin:/usr/lib/bin
See how we were called.
case "$1" in
start)
# Start daemon.
echo -n "Starting Tomcat: "
/opt/apache-tomcat-6.0.33/bin/startup.sh
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat ;;
stop)
# Stop daemons.
echo -n "Shutting down Tomcat: "
/opt/apache-tomcat-6.0.33/bin/shutdown.sh
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat ;;
restart)
$0 stop
$0 start
;;
condrestart)
[ -e /var/lock/subsys/tomcat ] && $0 restart ;;
status)
status tomcat
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
修改执行权限
[root@localhost ~]# chmod 755 tomcat
添加tomcat启动服务
[root@localhost ~]# chkconfig --add tomcat
设定开机自动启动
[root@localhost ~]# chkconfig tomcat on
服务开启关闭方式
[root@localhost ~]# service tomcat start #启动服务
[root@localhost ~]# /etc/init.d/tomcat start #启动服务
[root@localhost ~]# service tomcat stop #停止服务
[root@localhost ~]#/etc/init.d/tomcat stop #停止服务
设定好后可以重开机试试看。
更多的文章内容同步于FAQ-BOOK