1. 程式人生 > 其它 >tomcat管理指令碼

tomcat管理指令碼

 1 #!/bin/bash
  2 # #########################################################
  3 ###########################################################
  4 # chkconfig: 2345 96 14 ###################################
  5 # #########################################################
  6
  7 JDK_HOME=/apps/jdk
  8 CATALINA_HOME=/apps/tomcat
  
9 export JDK_HOME CATALINA_HOME 10 source /etc/profile 11 #PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` 12 #NUM=`ps -ef | grep -v grep | grep java | awk '{print $2}' | wc -l` 13 14 #case $1 in 15 start() { 16 echo "正在判斷服務狀態,請稍等!" 17 echo "請稍等3秒鐘" 18 echo
"3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 19 if netstat -ntpl | grep 8080 | grep LISTEN >/dev/null 20 then 21 echo "Tomcat已經正在運行了!" 22 else 23 echo "Tomcat沒有執行,1秒後啟動!" 24 echo 1;sleep 1 25 $CATALINA_HOME/bin/catalina.sh
start 26 echo "Tomcat 已經成功啟動完成,5秒後判斷是否啟動成功" 27 echo "5";sleep 1;echo "4";sleep 1 28 echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 29 if netstat -an | grep 8080 | grep LISTEN >/dev/null 30 then 31 PID=`ps -ef | grep tomcat | grep jdk | awk '{print $2}'` 32 NUM=`ps -ef | grep tomcat | grep jdk | awk '{print $2}' | wc -l` 33 echo "Tomcat 已經成功啟動${NUM} 個Tomcat程序!,PID為${PID}" 34 else 35 echo "Tomcat啟動失敗,請重新啟動!" 36 echo 1 37 fi 38 fi 39 } 40 stop() { 41 PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` 42 NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l` 43 echo "正在判斷服務狀態,請稍等3秒鐘!" 44 echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 45 if netstat -an | grep 8080 | grep LISTEN >/dev/null 46 then 47 echo "Tomcat執行中,1秒後關閉!" 48 echo 1;sleep 1 49 echo "即將關閉Tomcat服務,請稍等!" 50 $CATALINA_HOME/bin/catalina.sh stop ;echo "已經執行關閉命令,正在檢查關閉了多少Tomcat程序,請稍等30秒鐘!" 51 sleep 5 52 echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 53 # 此命令會關閉主機內所有java程序,慎用!! 54 pkill java && pkill tomcat 55 if netstat -an | grep 8080 | grep LISTEN >/dev/null;then 56 PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` 57 NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l` 58 kill -9 $PID ;echo "已成功關閉${NUM} 個tomcat程序" 59 else 60 echo "Tomcat 已經關閉完成!" 61 echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 62 fi 63 else 64 echo "Tomcat 沒有執行" 65 echo 1 66 fi 67 if netstat -an | grep 8080 | grep LISTEN >/dev/null;then 68 PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` 69 #NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l` 70 echo "關閉失敗,即將強制刪除tomcat程序!" 71 sleep 2 72 pkill tomcat ;sleep 2 73 if netstat -an | grep 8080 | grep LISTEN >/dev/null;then 74 echo "強制關閉失敗,即將再次強制刪除tomcat程序!" 75 pkill java; sleep 2 76 fi 77 fi 78 } 79 restart() { 80 stop 81 start 82 } 83 84 case "$1" in 85 start) 86 start 87 ;; 88 89 stop) 90 stop 91 ;; 92 93 restart) 94 restart 95 ;; 96 97 *) 98 echo $"Usage: $0 {start|stop|restart|status}" 99 esac
越學越感到自己的無知