linux tomcat自动部署shell

#!/bin/bash  
#defined   
TOMCAT_HOME="/usr/java/tomcat/tomcat"  
TOMCAT_PORT=80  
PROJECT="ROOT"  
#param validate  
 
 
#tomcat shutdown
sh  $TOMCAT_HOME/bin/shutdown.sh
echo "tomcat shutdown"
 
#check tomcat process  
tomcat_pid=`/usr/sbin/lsof -n -P -t -i :$TOMCAT_PORT`  
echo "current :" $tomcat_pid  
while [ -n "$tomcat_pid" ]  
do  
 sleep 5  
 tomcat_pid=`/usr/sbin/lsof -n -P -t -i :$TOMCAT_PORT`  
 echo "scan tomcat pid :" $tomcat_pid  
done  
#publish project  
echo "scan no tomcat pid,$PROJECT publishing"  
rm -rf "$TOMCAT_HOME"/webapps/$PROJECT*  
cp /root/.jenkins/workspace/shs/shs-console/target/shs-console-1.0-SNAPSHOT.war "$TOMCAT_HOME"/webapps/$PROJECT.war  
#bak project  
BAK_DIR=/save/bak/$PROJECT/`date +%Y%m%d`  
mkdir -p "$BAK_DIR"  
cp "$TOMCAT_HOME"/webapps/$PROJECT.war "$BAK_DIR"/"$PROJECT"_`date +%H%M%S`.war  
#remove tmp  
rm -rf /save/$PROJECT*.war  
#start tomcat  
"$TOMCAT_HOME"/bin/startup.sh  
echo "tomcat is starting,please try to access $PROJECT conslone url" 
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"

 

posted @ 2018-03-14 16:54  caozengling  阅读(987)  评论(0编辑  收藏  举报