一鍵發佈命令:./deploy.sh 項目war包 例如:./deploy.sh /home/test.warweb
說明:deploy.sh會先清空tomcat下的ROOT目錄,再將指定的war包加壓至ROOT目錄,最後執行restart.sh重啓tomcat。tomcat
代碼以下:app
#!/bin/shwebapp
war=$1
bin=$(cd `dirname $0`; pwd)rest
if [ ! -n "${war}" ]; then
echo "***Usage: $0 [project.war]"
exit 0
fi
if [ ! -f "${war}" ]; then
echo "***Error: ${war} does not exist."
exit 0
fi
if [ ! "${war##*.}" = "war" ]; then
echo "***Error: ${war} is not a war file."
exit 0
fi日誌
echo "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啓動日誌)ip
說明:restart.sh是用來重啓tomcat的,若是tomcat沒有啓動則直接啓動,若是已經啓動就先shutdown再啓動,若是shutdown以後3s沒有停掉tomcat進程,則kill掉原來的進程再啓動。it
代碼以下:test
#!/bin/sh
bin=$(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 -9 ${pid}
sleep 1
fi
fi
echo "Startup..." sh ${bin}/startup.sh if [ "$1" = "-v" ]; then tail -f ${bin}/../logs/catalina.out fi