使用shell脚本 启动关闭tomcat服务

前端之家收集整理的这篇文章主要介绍了使用shell脚本 启动关闭tomcat服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

步骤

1先备份webapps下的项目。

2把远程部署的项目拷贝到webapps目录下。

3删除远程部署的项目。

#!/bin/bash  
#defined   
TOMCAT_HOME="/usr/local/baofoo/batchpay"
TOMCAT_PORT=8080  
PROJECT="$1"  
#param validate  
if [ $# -lt 1 ]; then    
  echo "you must use like this : ./publish.sh <projectname> [tomcat port] [tomcat home dir]"    
  exit    
fi   
if [ "$2" != "" ]; then  
   TOMCAT_PORT=$2  
fi  
if [ "$3" != "" ]; then  
   TOMCAT_HOME="$3"  
fi  
#shutdown tomcat  
"$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"/work/* 
rm -rf "$TOMCAT_HOME"/logs/* 
#bak project  
BAK_DIR="$TOMCAT_HOME"/bak/$PROJECT/`date +%Y%m%d`  
mkdir -p "$BAK_DIR"
cp "$TOMCAT_HOME"/webapps/$PROJECT.war "$BAK_DIR"/"$PROJECT"_`date +%H%M%S`.war
rm -rf "$TOMCAT_HOME"/webapps/$PROJECT*  
cp "$TOMCAT_HOME"/$PROJECT.war "$TOMCAT_HOME"/webapps/$PROJECT.war
#remove tmp  
rm -rf "$TOMCAT_HOME"/$PROJECT*.war  
#start tomcat  
"$TOMCAT_HOME"/bin/startup.sh  
echo "tomcat is starting,please try to access $PROJECT conslone url"  
转载:http://jdkleo.iteye.com/blog/2159844 原文链接:https://www.f2er.com/bash/390778.html

猜你在找的Bash相关文章