posts - 167,  comments - 30,  trackbacks - 0
          #!/bin/bash
          # Title   : {stop|start|restart} Tomcat . Default is "restart".
          # Author  : Cheng PJ
          # E-mail  : 7looki@gmail.com
          # Version : 1.0
          export PATH=/bin:/sbin:/usr/bin:/usr/sbin
          file_name_f1=`echo ${0} | awk -F / '{print $1}'`
          file_name_f2=`echo ${0} | awk -F / '{print $NF}'`
          file_pwd=`echo ${0} | sed 's#'/${file_name_f2}'$##g'`
          if [ -z "${file_name_f1}" ] || [ ${file_name_f1} != ${file_name_f2} ]; then
              cd ${file_pwd}
          fi
          tomcat_bin=`pwd`
          if [ ! -f ${tomcat_bin}/startup.sh ] || [ ! -f ${tomcat_bin}/bootstrap.jar ] || [ ! -f ${tomcat_bin}/catalina.sh ]; then
              echo ""
              echo "This script must be in the directory under \${Tomcat_Home}/bin !"
              echo ""
              exit 1
          fi
          tomcat_whoami=`whoami`
          tomcat_own_user=`ls -l ${tomcat_bin}/startup.sh | awk '{print $3}'`
          tomcat_who_run=`ps -ef | grep ${tomcat_bin} |  grep -v "grep\|${0}" | awk '{print $1}'`
          tomcat_who_run_other=`ps -ef | grep ${tomcat_bin} | grep -v "grep\|${0}" | awk '{print $1}' | grep -v "${tomcat_who_run}\|root" | sort | uniq`
          tomcat_run_num=`ps -ef | grep ${tomcat_bin} |  grep -v "grep\|${0}" | wc -l`
          tomcat_echo_stop () {
              echo "Tomcat Stopping ...          [OK]"
              echo ""
          }
          tomcat_echo_start () {
              echo ""
              echo "Tomcat Starting ...          [OK]"
          }
          tomcat_echo_error () {
              echo ""
              echo "Tomcat Stopped ERROR ! Please check privilege or something !"
              echo ""
              exit 1
          }
          tomcat_stop () {
              if [ ${tomcat_who_run} == ${tomcat_whoami} ] || [ ${tomcat_whoami} == "root" ]; then
                  ps -ef | grep ${tomcat_bin} |  grep -v "grep\|${0}" | awk '{print $2}' | xargs kill -9
                  if [ $? -eq 0 ]; then
                      tomcat_echo_stop;
                  else
                      tomcat_echo_error;
                  fi
                  
              else
                  echo "ERROR ! You must root or ${tomcat_who_run} to run this script !"
                  exit 1
              fi
          }
          tomcat_start () {
              if [ ${tomcat_own_user} == ${tomcat_whoami} ] || [ ${tomcat_own_user} == "root" ]; then
                  sh ${tomcat_bin}/startup.sh
                  if [ $? -eq 0 ]; then
                      tomcat_echo_start;
                  else
                      tomcat_echo_error;
                  fi
              else
                  echo "ERROR ! You must root or ${tomcat_own_user} to run this script !"
                  exit 1
              fi
          }
          tomcat_shutdown () {
              if [ ${tomcat_run_num} -eq 0 ]; then
                  echo "Tomcat is not running!"
                  echo ""
              elif [ ${tomcat_run_num} -eq 1 ]; then
                  tomcat_stop;
              else
                  if [ ${tomcat_who_run_other} == "" ]; then
                      tomcat_stop;
           
                  else
                      echo "Please shutdown Tomcat with other users (${tomcat_who_run_other}) "
                      echo "Tomcat is not stopped !"
                      exit 1
                  fi
              fi
          }
          tomcat_startup () {
              tomcat_run_check=`ps -ef | grep ${tomcat_bin} |  grep -v "grep\|${0}" | wc -l`
              if [ ${tomcat_run_check} -eq 0 ]; then
                  tomcat_start;
              else
                  echo "Tomcat is not stopped ! Please stop Tomcat at first !"
                  echo 1
              fi
          }
          case "$1" in
              start|-start|--start)
                  tomcat_startup
                  ;;
              stop|-stop|--stop)
                  tomcat_shutdown
                  ;;
              help|-help|--help)
                  echo ""
                  echo "This script used for {start|stop|restart} Tomcat !"
                  echo ""
                  echo "                                      By ST.7looki"
                  echo "                                  7looki@gmail.com"
                  echo ""
                  ;;
              restart|-restart|--restart|*)
                  tomcat_shutdown
                  sleep 1
                  tomcat_startup
          esac
          posted on 2013-01-30 10:48 David1228 閱讀(1492) 評論(2)  編輯  收藏 所屬分類: 應用服務器

          FeedBack:
          # re: tomcat-restart shell腳本
          2013-01-30 16:42 | 免費網絡記事本
          這個不需要每次kill吧  回復  更多評論
            
          # re: tomcat-restart shell腳本[未登錄]
          2013-01-30 17:01 | david
          @免費網絡記事本
          hi,也可以直接使用shutdown.sh,不過直接kill更快些,你說的每次都kill是什么意思呢?,restart腳本執行后stop中不就kill一次就ok了么。  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          Java

          Linux知識相關

          Spring相關

          云計算/Linux/虛擬化技術/

          友情博客

          多線程并發編程

          開源技術

          持久層技術相關

          搜索

          •  

          積分與排名

          • 積分 - 359229
          • 排名 - 154

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 五台县| 绩溪县| 曲水县| 车致| 孝义市| 泽普县| 牟定县| 浦江县| 武鸣县| 察隅县| 昔阳县| 温州市| 彝良县| 千阳县| 青海省| 青岛市| 额尔古纳市| 隆尧县| 上饶县| 萍乡市| 磴口县| 宁夏| 吕梁市| 密云县| 申扎县| 临江市| 江孜县| 东山县| 手游| 洛隆县| 海伦市| 靖宇县| 营山县| 望奎县| 怀化市| 任丘市| 汶上县| 洛扎县| 青海省| 阿尔山市| 古丈县|