转载请注明出处:http://blog.csdn.net/l1028386804/article/details/78666356
直接上代码:
#!/bin/sh ## java env
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_144
export JRE_HOME=$JAVA_HOME/jre ## service name
SERVICE_NAME="tomcat_service"case "$1" in start) /usr/local/tomcat/test-tomcat-10000/bin/startup.sh ;; stop) sleep 5 ## ## edu-service-aa.jar ## edu-service-aa-bb.jar P_ID=`ps -ef | grep -w "test-tomcat-10000" | grep -v "grep" | awk '{print $2}'` if [ "$P_ID" == "" ]; then echo "=== $SERVICE_NAME process not exists or stop success" else echo "=== $SERVICE_NAME process pid is:$P_ID" echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID" kill $P_ID fi ;; restart) $0 stop sleep 2 $0 start echo "=== restart $SERVICE_NAME" ;; *) ## restart $0 stop sleep 2 $0 start ;; esac
exit 0