Configure Tomcat to Run as a Service.

We will now see how to run Tomcat as a service and create a simple Start/Stop/Restart script, as well as to start Tomcat at boot.

Change to the /etc/init.d directory and create a script called 'tomcat' as shown below.

view plaincopy to clipboardprint?

[root@srv6 share]# cd /etc/init.d
[root@srv6 init.d]# vi tomcat

内容

#!/bin/bash  
# description: Tomcat Start Stop Restart  
# processname: tomcat  
# chkconfig: 234 20 80  
JAVA_HOME=/usr/java/jdk1.7.0_05  
export JAVA_HOME  
PATH=$JAVA_HOME/bin:$PATH  
export PATH  
CATALINA_HOME=/usr/share/apache-tomcat-7.0.29  
  
case $1 in  
start)  
sh $CATALINA_HOME/bin/startup.sh  
;;   
stop)     
sh $CATALINA_HOME/bin/shutdown.sh  
;;   
restart)  
sh $CATALINA_HOME/bin/shutdown.sh  
sh $CATALINA_HOME/bin/startup.sh  
;;   
esac      
exit 0

配权限

[root@srv6 init.d]# chmod 755 tomcat

设置开机启动

[root@srv6 init.d]# chkconfig --add tomcat
[root@srv6 init.d]# chkconfig --level 234 tomcat on

校验

[root@srv6 init.d]# chkconfig --list tomcat
tomcat 0:off 1:off 2:on 3:on 4:on 5:off 6:off

启动tomcat

[root@srv6 ~]# service tomcat start
Using CATALINA_BASE: /usr/share/apache-tomcat-7.0.29
Using CATALINA_HOME: /usr/share/apache-tomcat-7.0.29
Using CATALINA_TMPDIR: /usr/share/apache-tomcat-7.0.29/temp
Using JRE_HOME: /usr/java/jdk1.7.0_05
Using CLASSPATH: /usr/share/apache-tomcat-7.0.29/bin/bootstrap.jar:/usr/share/apache-tomcat-7.0.29/bin/tomcat-juli.jar

标签: none

添加新评论