service配置腳本,“/etc/init.d/tomcat”,實現通過"service tomcat status " 查看tomcat狀態,並輸出PID,見腳本
# description: Tomcat Start Stop Restart Status JAVA_HOME=/usr/share/jdk1.8.0_65 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH CATALINA_HOME=/usr/share/tomcat-8.5.14 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 ;; status) ps -ef | grep tomcat | grep bootstrap.jar |grep start >>null if [ $? -ne 0 ] then echo "tomcat stoped" else ps -ef | grep tomcat | grep bootstrap.jar |grep start | awk '{print "tomcat pid: "$2}' echo "tomcat is runing....." fi esac exit 0
btw,別忘了給tomcat添加執行屬性。