tomcat Rapid Release backup script

I. Description

  Every time we release a new war in tomcat package, always go through [Backup - stop - upload - start] these parts, which links and upload speeds of great relevance, if the speed is very slow, then the whole release time will be very long.

  If we do not release the aid of automated tools, we can pre-package uploaded war to the specified directory, and then use the shell script to complete the [Backup - down - copy - start], will replace the upload action for the copy action, this time not released dependent on the speed.

II. Directory Structure

III. Script

# ! / Bin / the bash 
# checks required files 
# determines whether there is a war package 
IF [! -F  " /home/ap/warDir/client.war " ]; the then 
echo " /home/ap/warDir/client.war not exist, please upload " 
Exit 
fi 

# Find tomcat process 
tomcat_pid =` PS -ef | grep the Apache-tomcat-7.0.85 | grep -v grep | awk '{Print $ 2 }' `
 IF [ " $ tomcat_pid " == " " ]; the then 
echo " Tomcat is not running " 
the else 
PS -ef | grep the Apache-Tomcat-7.0.85 | grep -v grep | awk '{print $2} '| Xargs the kill -9 
echo " tomcat has stopped " 
fi 

# Clear the cache tomcat 
RM -rf /home/ap/apache-tomcat-7.0.85/work/Catalina/localhost/* 
echo " clean up tomcat caching completion " 

# judge backup folder exists 
iF [-d! " /home/ap/apache-tomcat-7.0.85/backup/ " ]; the then 
mkdir /home/ap/apache-tomcat-7.0.85/ backup 
echo " backup folder Creating successful " 
fi 
# backup files 
# before cp to add \, otherwise equivalent to cp cp -i, -f it will not take effect 
\ cp -f /home/ap/apache-tomcat-7.0.85/webapps/* .war /home/ap/apache-tomcat-7.0.85/Backup 
echo " file backup success " 

# Clear tomcat webapps directory 
RM -rf /home/ap/apache-tomcat-7.0.85/webapps/* 
echo " clean up the webapps directory successfully " 

# copy the new war package to the webapps directory 
cp -f / Home / the AP / warDir / *. war /home/ap/apache-tomcat-7.0.85/ webapps 
echo " new war package has been copied to the webapps directory " 

# start Tomcat 
cd /home/ap/apache-tomcat-7.0.85 / bin 
echo " #################### " 
echo " ## started ## Tomcat " 
echo " ############# ####### " 
./startup.sh & tail -f ../logs/catalina.out

IV. Notes

1. note the clear path to the script, we need to replace the path cost of the machine and environment information

2.rm -rf command, it is best to write the absolute path to avoid because the folder does not exist causes the root directory of the deleted

3. according to the needs, to customize more features

V. Other

Stop the tomcat script

ps -ef | grep apache-tomcat-7.0.85 | grep -v grep | awk '{print $ 2 }' | xargs kill -9

 

Guess you like

Origin www.cnblogs.com/xiayuscc/p/10968916.html