快速部署Tomcat項目的Shell指令碼,tomcatshell

來源:互聯網
上載者:User

[轉] 快速部署Tomcat項目的Shell指令碼,tomcatshell

  為了做叢集測試,在每台機器上裝了3個tomcat,每次發布項目的時候都要反覆敲一些命令,重啟tomcat之前先檢查tomcat進程有沒有停掉,沒有還要手動kill該進程。

  發布次數多了,操作就比較繁瑣了,索性寫個指令碼一鍵發布,省時省力^_^。

  把deploy.sh和restart.sh分別拷貝到3個tomcat的bin目錄下,再用chmod +x給這兩個指令碼賦上可執行許可權。

  一鍵發布命令:./deploy.sh 項目war包    例如:./deploy.sh /home/test.war

  說明:deploy.sh會先清空tomcat下的ROOT目錄,再將指定的war包加壓至ROOT目錄,最後執行restart.sh重啟tomcat。

代碼如下:

#!/bin/shwar=$1bin=$(cd `dirname $0`; pwd)if [ ! -n "${war}" ]; then    echo "***Usage: $0 [project.war]"    exit 0fiif [ ! -f "${war}" ]; then    echo "***Error: ${war} does not exist."    exit 0fiif [ ! "${war##*.}" = "war" ]; then    echo "***Error: ${war} is not a war file."    exit 0fiecho "Deploy ${war##*/}..."rm -rf ${bin}/../webapps/ROOT/ && unzip -qo ${war} -d ${bin}/../webapps/ROOT/rm -rf ${bin}/../work/Catalina/localhost/echo "Restart tomcat..."exec ${bin}/restart.sh

  如需重啟tomcat則使用命令:./restart.sh 或 ./restart.sh -v (參數-v表示啟動時列印tomcat開機記錄)

  說明:restart.sh是用來重啟tomcat的,如果tomcat沒有啟動則直接啟動,如果已經啟動就先shutdown再啟動,如果shutdown之後3s沒有停掉tomcat進程,則kill掉原來的進程再啟動。

代碼如下:

#!/bin/shbin=$(cd `dirname $0`; pwd)pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}') if [ -n "${pid}" ]; then    echo "Shutdown..."    sh ${bin}/shutdown.sh    sleep 3    pid=$(ps aux | grep tomcat | grep -v grep | grep -v restart | grep ${bin} | awk '{print $2}')    if [ -n "${pid}" ]; then        kill ${pid}        sleep 1    fifiecho "Startup..."sh ${bin}/startup.shif [ "$1" = "-v" ]; then    tail -f -n 600 ${bin}/../logs/catalina.outfi

本人用的是CentOS,3個tomcat分別在/opt/apache-tomcat-7.0.65/下的8080/8081/8082子目錄下,監聽8080/8081/8082連接埠。運行如下:

最後在瀏覽器裡輸入 http://localhost:8080 即可訪問。

原文連結:https://www.linuxidc.com/Linux/2016-01/127258.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.