tomcat自动发布脚本
把myeclipse打包处理的java项目放到/tmp目录下,再执行这个脚本,会达到杀掉tomcat进行,升级前备份,删除旧项目,解压新项目,更改配置,启动进程的功能.可以对多个项目进行升级.
- #!/bin/bash
- #make by mojigan
- #time 2012-1019
- #version 1.3
- #upgrade the project
- #define some value.
- network_dir="/data/webapps/iosm_apps/networkresourcemanage_apps/current"
- network_back="/data/webapps/iosm_apps/networkresourcemanage_apps/backup/networkresource"
- operate_dir="/data/webapps/iosm_apps/operationservice_apps/current"
- operate_back="/data/webapps/iosm_apps/operationservice_apps/backup/operationservice"
- tomcat_progrm="/opt/tomcat/apache-tomcat-6.0.33_iosm"
- instance="apache-tomcat-6.0.33_iosm"
- owner=iosmtomcat
- function running(){
- b=''
- for ((i=0;i<=100;i+=2))
- do
- printf "progress:[%-50s]%d%%\r" $b $i
- sleep 0.2
- b=#$b
- done
- echo
- }
- #the user
- user=$(id -un)
- if [ ${ user} != "$owner" ];then
- echo "==>the program must run by iosmtomcat<=="
- exit 1
- fi
- #the file must exits.
- operationservice=$(find /tmp -type f -mtime -1 -user ${owner} -name "operationservice.war")
- networkresource=$(find /tmp -type f -mtime -1 -user ${owner} -name "networkresourcemanage.war")
- if [ -z "$networkresource" -a -z "$operationservice" ];then
- echo "we don't upgrade anything."
- exit 1
- else
- echo "when you run this script,it will upgrade the project $networkresource and $operationservice "
- read -p "would you like do that?(yes/no)" yesno
- if [ ${yesno} != "yes" ];then
- echo "you stop the bash script,we don't upgrade the project."
- exit 1
- fi
- fi
- #kill tomcat pid
- echo "kill the tomcat service instance,please hold on 5 seconds........."
- ps aux | grep $instance | grep -v grep | awk '{print "kill ",$2|"bash"}'
- running
- ps aux | grep $instance | grep -v grep
- #main work
- #backup remove pack
- echo "#main work"
- echo "#backup remove pack"
- if [ -n "$networkresource" ];then
- cp -R ${network_dir} ${network_back}_$(date "+%Y%m%d_%H%M")
- [ $? -ne 0 ] && exit 1
- echo "##cp#####################################################################"
- cd ${network_dir}
- pwd
- [ $? -ne 0 ] && exit 1
- echo "##cd#####################################################################"
- ls -l ${network_dir} | awk '$0~/^-/ || $0~/^d/{print "rm -rf ",$NF|"bash"}'
- [ $? -ne 0 ] && exit 1
- echo "##rm#####################################################################"
- mv ${networkresource} ${network_dir}
- [ $? -ne 0 ] && exit 1
- echo "##mv#####################################################################"
- jar -xf ${network_dir}/networkresourcemanage.war
- [ $? -ne 0 ] && exit 1
- echo "##jar#####################################################################"
- fi
- if [ -n "$operationservice" ];then
- cp -R ${operate_dir} ${operate_back}_$(date "+%Y%m%d_%H%M")
- [ $? -ne 0 ] && exit 1
- echo "##cp#####################################################################"
- cd ${operate_dir}
- pwd
- [ $? -ne 0 ] && exit 1
- echo "###cd####################################################################"
- ls -l ${operate_dir} | awk '$0~/^-/ || $0~/^d/{print "rm -rf",$NF|"bash"}'
- [ $? -ne 0 ] && exit 1
- echo "##rm#####################################################################"
- mv ${operationservice} ${operate_dir}
- [ $? -ne 0 ] && exit 1
- echo "##mv#####################################################################"
- jar -xf ${operate_dir}/operationservice.war
- [ $? -ne 0 ] && exit 1
- echo "##jar#####################################################################"
- fi
- #cpp something.
- OPERDATA='/opt/tomcat/apache-tomcat-6.0.33_iosm/bin/copy/op'
- OPERCURRENT='/data/webapps/iosm_apps/operationservice_apps/current/WEB-INF/classes'
- cp -f $OPERDATA/CasServerConfig.properties $OPERCURRENT/
- cp -f $OPERDATA/InterfaceURLConfig.properties $OPERCURRENT/
- cp -f $OPERDATA/system-datasource-config.xml $OPERCURRENT/datasource/
- cp -f $OPERDATA/net-system-datasource-config.xml $OPERCURRENT/datasource/
- cp -f $OPERDATA/datasource-appcontx.xml $OPERCURRENT/com/iscreate/conf/spring/
- cp -f $OPERDATA/login-ldap-appcontx.xml $OPERCURRENT/com/iscreate/conf/spring/
- NETDATA='/opt/tomcat/apache-tomcat-6.0.33_iosm/bin/copy/net'
- NETCURRENT='/data/webapps/iosm_apps/networkresourcemanage_apps/current/WEB-INF/classes'
- cp -f $NETDATA/system-datasource-config.xml $NETCURRENT/datasource/
- cp -f $NETDATA/CasServerConfig.properties $NETCURRENT/
- #startup tomcat server
- echo "#startup tomcat server"
- echo ${tomcat_progrm}/bin/startup.sh
- ${tomcat_progrm}/bin/startup.sh
- #view logs
- echo "#view logs"
- running
- running
- tail -f ${tomcat_progrm}/logs/catalina.out