标签:tomcat
#!/bin/bash
#defined
now=`date +%Y%m%d%H%M%S`
TOMCAT_HOME="/usr/tomcat7/apache-tomcat-7.0.70/"
TOMCAT_PORT=8080
PROJECT="$1"
BACKUP_DIR="/tomcat_back/$PROJECT/$now"
#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`
tomcat_pid=`ps aux|grep "java"|grep "$TOMCAT_HOME"|awk ‘{printf $2}‘`
while [ -n "$tomcat_pid" ]
do
echo "current :" $tomcat_pid
kill -9 $tomcat_pid
echo "scan tomcat pid :" $tomcat_pid
done
#publish project
echo "scan no tomcat pid,$PROJECT publishing"
rm -rf "$TOMCAT_HOME"/webapps/$PROJECT*
cp /save/$PROJECT*.war "$TOMCAT_HOME"/webapps/$PROJECT.war
#bak project and may be create backup dir
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR"
fi
cp "$TOMCAT_HOME"/webapps/$PROJECT.war "$BACKUP_DIR"/"$PROJECT"_`date +%H%M%S`.war
#remove tmp
rm -rf /save/$PROJECT*.war
#start tomcat
"$TOMCAT_HOME"/bin/startup.sh
tail -10f "$TOMCAT_HOME/logs/catalina.out"
echo "#############################################################"
echo "tomcat is starting,please try to access $PROJECT conslone url"
echo "#############################################################"
每一步的注释还算清楚,因为公司项目本身没有采用专业的源码管理工具来管理项目,所以此脚本还要准备好相应的不同平台的配置文件,需要更改默认的项目配置文件,如果有专业的源码管理,那就不用这么啰嗦了,直接使用该脚本就可以部署tomcat的工程了
标签:tomcat
原文地址:http://5404542.blog.51cto.com/5394542/1843032