tomcat automated deployment script

   A simple tomcat automated deployment script that implements the following functions:

 

   (1) Check whether the tomcat process exists, if it exists, kill it

   (2) Backup the existing war package to the tomcat/backup directory

    (3) Copy the new war package from the current directory to the tomcat/webapps directory

  (4) Start 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
be
# change color
echo -e "\033[34m"
#create backup dir
if [ ! -d "$backupPath" ]; then
  mkdir "$backupPath"
be
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;
be

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";
be

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

   

 

   When using, you need to modify the value of tomcatPath to the actual tomcat path.

 

    Save the file to autodeploy.sh and execute the command: 

./autodeploy.sh  abc

   abc is the name of the war package to be released, that is, there are two files in the current directory:

   autodeploy.sh and abc.war

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326905964&siteId=291194637