#! / bin / bash JDK_HOME = / apps / jdk1. 7 .0_79 CATALINA_HOME = / apps / Tomcat export JDK_HOME CATALINA_HOME source / etc / profile #PID = ` ps -ef | grep -v grep | grep java | awk ' {print $ 2} ' ` #NUM =` ps -ef | grep -v grep | grep java | awk ' {print $ 2} ' | wc - l` #Case $ . 1 in Start () { echo " Determining the service status, wait! " echo " Please wait 3 seconds " echo " 3 " ; SLEEP . 1 ; echo " 2 " ; SLEEP . 1 ; echo " . 1 " ; SLEEP 1 IF netstat -an | grep 8080 | grep LISTEN> / dev / null the then echo " ! Tomcat is already running " the else echo "Tomcat is not running, 1 second to start! " Echo . 1 ; SLEEP . 1 $ CATALINA_HOME . / Bin / Catalina SH Start echo " the Tomcat started successfully completed, after 5 seconds is determined whether a successful start " echo " . 5 " ; SLEEP . 1 ; echo " . 4 " ; SLEEP . 1 echo " . 3 " ; SLEEP . 1 ; echo " 2 " ; SLEEP . 1 ; echo " . 1 "; SLEEP . 1 IF the netstat -an | grep 8080 | grep the LISTEN> / dev / null the then the PID = ` PS -ef | grep Tomcat | grep JDK | awk ' {2} Print $ ' ` NUM = ` PS -ef | grep Tomcat | grep the JDK | awk ' {Print $ 2} ' | WC - l` echo " Tomcat has started successfully $ {NUM} a Tomcat process, PID is $ {PID}!" The else echo " Tomcat failed to start, restart! " Echo . 1 Fi Fi } STOP () { the PID =` PS -ef | grep -v grep | grep Java | awk ' {2} Print $ ' ` NUM =` PS -ef | grep -v " Color " | grep Tomcat | awk ' {2} Print $ ' | WC - l` echo " Determining service status, please wait 3 seconds! " echo " 3 " ; SLEEP 1 ; echo " 2 " ; SLEEP 1 ; echo " 1 " ; SLEEP 1 IF netstat -an | grep 8080 | grep LISTEN> / dev / null the then echo " Tomcat is running, shut down after one second! " echo 1 ; SLEEP 1 echo " ! Tomcat service will be shut down, please wait " $ CATALINA_HOME/ bin / catalina. SH STOP; echo " has been performed to close the command, how much is being checked shut Tomcat process, please wait 30 seconds! " SLEEP 2 echo " 3 " ; SLEEP 1 ; echo " 2 " ; SLEEP 1 ; echo " 1 " ; SLEEP 1 pkill the Java && pkill Tomcat IF netstat -an | grep 8080 | grep LISTEN> / dev / null ; the then PID`= PS -ef | grep -v grep | grep Java | awk ' {2} Print $ ' ` NUM = ` PS -ef | grep -v " Color " | grep Tomcat | awk ' {2} Print $ ' | WC - L ` the kill - 9 $ PID; echo " has successfully closed a $ {NUM} tomcat process , " the else echo " Tomcat has been closed to complete! " echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 fi else echo "Tomcat 没有运行" echo 1 fi if netstat -an | grep 8080 | grep LISTEN >/dev/null;then PID=`ps -ef | grep -v grep | grepthe Java | awk ' {Print $ 2} ' ` #NUM =` PS -ef | grep -v " Color " | grep tomcat | awk ' {Print $ 2} ' | WC - l` echo " failed to close, about to force the removal process tomcat ! " SLEEP 2 pkill Tomcat; SLEEP 2 IF netstat -an | grep 8080 | grep LISTEN> / dev / null ; the then echo "Failure forced to close, once again about to force the removal of tomcat process! " Pkill the Java; SLEEP 2 fi fi } restart () { STOP Start } Case " $ 1 " in Start) Start ;; STOP) STOP ;; restart) restart ;; * ) echo $ " Usage: $ 0 {Start | STOP | restart | Status} " esac