Add Tomcat to Service

STEP: 增加啟動/關閉腳本,其中藍色部分是重點,必須要填寫此部分才能夠讓chkconfig識別

vi /etc/init.d/tomcat

#!/bin/bash

# description: Tomcat Start Stop Restart

# processname: tomcat

# chkconfig: 345 20 80


export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45

export TOMCAT_HOME=/opt/apache-tomcat-7.0.50


case $1 in

start)

       sh $TOMCAT_HOME/bin/startup.sh

       ;;

stop)

       sh $TOMCAT_HOME/bin/shutdown.sh

       ;;

restart)

       sh $TOMCAT_HOME/bin/shutdown.sh

       sh $TOMCAT_HOME/bin/startup.sh

       ;;

status)

       ps -ef | grep tomcat

       ;;

esac

exit 0


STEP2: 設定可執行權限給user

chmod 755 /etc/init.d/tomcat


STEP3: 設定rc1.d, rc2.d

ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat

ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat


STEP4: 使用chkconfig增加到服務

chkconfig --add tomcat
Comments