#!/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 "----------------------------------------------------------------------------"
05-23 07:03