deploy automation script

In order to make our process automation and make free of error, we build automation script for deploy. Following script will download war file from maven repository and deploy to tomcat.

 

#!/bin/sh 

TOMCAT_HOME=/opt/tomcat

if [ -z $PROJECT]; then
        PS3="Please choose:"
        PROJECTS="project1 project2"
        echo "Choose which project you want to deploy from the list below:"
        select PROJECT in $PROJECTS;
        do
                case $PROJECT in
                project1)
                        REPO_PATH=com/yuan/project1
                        PRJ_NAME=project1
                        break;;
                esac  
        done
fi 

if [ -z $PROJECT ]; then
        echo "Error in select project!"
        exit 1 
fi

read -p "Please enter which version you want to deploy:" PRJ_VERSION


WAR_FILE="http://build.yuan.com:9999/repository/"$REPO_PATH"/"$PRJ_VERSION"/"$PRJ_NAME"-"$PRJ_VERSION".war"

echo "Project Name="$PRJ_NAME
echo "WAR location="$WAR_FILE
echo "TOMCAT_HOME=" $TOMCAT_HOME

WORKING_DIR=~/tmp

echo "Working Dir=" $WORKING_DIR

echo "---clean working dir..."
if [ -d $WORKING_DIR ]
then
        rm -fR $WORKING_DIR
fi
mkdir $WORKING_DIR

cd $WORKING_DIR
echo "Get war file..."
wget $WAR_FILE
if [ $? -ne 0 ]; then
        exit 1
fi

echo "shutdown tomcat..."
$TOMCAT_HOME/bin/shutdown.sh
# wait 6 seconds after a clean shutdown before killing

      count=1
      pids=`ps aux | grep java | grep catalina | awk '{print $2}'`
      while [ $count -ne 6 ] && [ -n "$pids" ];
      do
          echo "Waiting 1s on TOMCAT java pids: $pids"
          sleep 1
          count=$(( $count + 1))
          pids=`ps aux | grep java | grep catalina | awk '{print $2}'`
      done

      # kill if anything is still around

      if [ -n "$pids" ]; then
          pkill -9 $pids
      fi

echo "deploy war to tomcat..."
rm -rf $TOMCAT_HOME/webapps/$PRJ_NAME/
rm -rf $TOMCAT_HOME/webapps/$PRJ_NAME.war
cp $WORKING_DIR/$PRJ_NAME-$PRJ_VERSION.war $TOMCAT_HOME/webapps/$PRJ_NAME.war

echo "start tomcat..."
$TOMCAT_HOME/bin/startup.sh

echo "done."
 

你可能感兴趣的:(tomcat,maven)