tomcat自动化部署脚本

   一个简单的tomcat自动化部署脚本 ,实现功能:

 

   (1) 检查tomcat进程是否存在,如果存在则kill掉

   (2) 备份现有war包到tomcat/backup目录

    (3) 复制当前目录新war包到tomcat/webapps目录

  (4) 启动tomcat

 

#!/bin/bash
now=`date +%Y%m%d%H%M%S`
tomcatPath=/home/tomcat/software/tomcat6
backupPath=/home/tomcat/software/tomcat6/backup
war=$1

if [ -e "$war.war" ]; then
  echo -e "\033[34m war archive: $war.war \033[0m"
else 
  echo -e "\033[31m war archive '$war.war' not exists \033[0m"
  exit -1
fi
# change color
echo -e "\033[34m"
#create backup dir
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 "\033[32m"
echo 'startup tomcat...'

sh $tomcatPath/bin/startup.sh

tail -10f $tomcatPath/logs/catalina.out

   

 

   使用时,需要先修改tomcatPath的值为实际tomcat路径。

 

    保存该文件到autodeploy.sh, 执行命令: 

./autodeploy.sh  abc

   abc为待发布的war包名称,即当前目录存在两个文件:

   autodeploy.sh和abc.war



已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐
  • —软件人才免语言低担保 赴美带薪读研!—



你可能感兴趣的:(tomcat,自动化,脚本)