linux implements automatic deployment of tomcat scripts

  • 2020-05-27 07:59:18
  • OfStack

Due to the frequent deployment of war to tomccat, there is often a lot of repetitive work to do: stop service, back up the war package, upload the new war package, and start the service. Simply wrote an automatic deployment script.

The script is autoDeploy.sh:


#! /bin/sh
echo '#################### Start automatic deployment ####################'
path=`pwd` # The current path 
tomcatPath=tomcat-7 # The specified tomcat File directory name 
cd ../$tomcatPath/bin # Enter the tomcat the bin directory 
PID=$(ps -fu `whoami`|grep tomcat|grep -v grep|awk '{print $2}')
if [ -z "$PID" ];then
 echo "no tomcat process"
else
./shutdown.sh # stop tomcat service 
fi
sleep 1 # dormancy 1s
cd ../webapps # Enter the tomcat the webapps directory 
rm -fr test # delete test File directory 
mv test.war test.war.$(date +%Y%m%d) # The backup webapps Under the test16 cp $path/test.war ./ # copy test.war to webapps Under the path 
sleep 1 # dormancy 1s
cd ../bin
./startup.sh # Start the tomcat service 
echo '#################### End of the deployment ####################'

Description:

1. Create a new directory autoDeploy and tomcat and put them in the same directory

(1)autoDeploy.sh is placed in the autoDeploy directory

(2) the test.war to be deployed is placed in the autoDeploy directory (test.war is the war package to be deployed on tomcat)

2.tomcatPath= tomcat-7 (specify the tomcat file directory name, tomcat-7 change to the directory name of your own tomcat)

3. Execute autoDepoy.sh to achieve automatic deployment

autoDepoy.sh new autoDepoy.sh if you do not have execute permissions, you need to execute: chmod +x autoDeploy.sh


Related articles: