Tomcat通过脚本自动部署

http://t.zoukankan.com/yshyee-p-11866140.html

 

1:autodeploy_tomcat_app.sh

now=`date +%Y%m%d%H%M%S`
tomcatPath=/home/test/apache-tomcat-8.5.34
backupPath=/home/test/apache-tomcat-8.5.34/backup
war=$1

if [ -e "$war.war" ];then
        echo -e "war archive: $war.war"
else
        echo -e "war archive '$war.war' not exists"
        exit -1
fi

if [ ! -d "$backupPath" ]; then
  mkdir "$backupPath"
fi

echo "tomcat home: $tomcatPath"
echo "backup path: $backupPath"
echo 'try to stop tomcat...'

pid=`ps aux|grep "java"|grep "$tomcatPath"|awk '{printf $2}'`
if [ -n $pid ]; then
  echo "tomcat pid: $pid";
  kill -9 $pid;
fi

echo 'stop tomcat finished...'
echo 'backup old archive...'

if [ -f "$tomcatPath/webapps/$war.war" ]; then
  mv -v "$tomcatPath/webapps/$war.war" "$backupPath/$1_$now.war";
fi

rm -rf $tomcatPath/webapps/$war*
echo "copy $war.war archive to webapps.."
cp -v "$war.war" "$tomcatPath/webapps/"

echo -e "33[32m"
echo 'startup tomcat...'

sh $tomcatPath/bin/startup.sh

sleep 3

tail -f $tomcatPath/logs/catalina.out

2:将test.war上传至/home/test/apache-tomcat-8.5.34目录,然后执行以下脚本进行部署

sh autodeploy_tomcat_app.sh test

 

posted on 2023-01-05 08:50  四海骄阳  阅读(43)  评论(0编辑  收藏  举报

导航