
service配置脚本,“/etc/init.d/tomcat”,实现通过"service tomcat status " 查看tomcat状态,并输出PID,见脚本
# description: Tomcat Start Stop Restart Status JAVA_HOME=/usr/share/jdk1..0_65
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/tomcat-8.5. case $ 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 ]
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
btw,别忘了给tomcat添加执行属性。