Tomcat pool 发布脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tomcat pool 发布脚本相关的知识,希望对你有一定的参考价值。
首先这边是乙方,项目多,系统多。新上线的项目都是脚本去做发布,早上又赶了套脚本。
之前公司有兄弟运行了下面这套脚本未加参数,说静态资源未发成功,tomcat 和发布系统的agent反而给干没了,于是又做了点优化,加了参数判断。
$ cat copy_h5_mall_new.sh #!/bin/sh #copy h5 mall nginx_static_ip=10.10.13.37 time_stamp=`date +"%Y-%m-%d-%H-%M-%S"` h5_mall_zip_name=$1 war_md5=`md5sum ../static/${h5_mall_zip_name} | awk ‘{print $1}‘` md5_file=`cat ../static/${h5_mall_zip_name}.md5 | awk ‘{print $1}‘` if [ $# -ne "1" ];then echo "不看脚本就运行,干死你!" else if [ "${war_md5}" = "${md5_file}" ];then ssh ${nginx_static_ip} "cp -r /data/desheng/h5_mall /data/desheng/h5_mall-${time_stamp}" ssh ${nginx_static_ip} "cd /data/desheng/h5_mall && /bin/rm -rf *" scp ../static/${h5_mall_zip_name} ${nginx_static_ip}:/data/desheng/h5_mall ssh ${nginx_static_ip} "cd /data/desheng/h5_mall && unzip ${h5_mall_zip_name}" ip_list=`cat ../env.sh | grep "frontier-cms-web" | cut -d "=" -f1 | cut -d "#" -f2 | uniq` for ip in ${ip_list[*]};do ssh $ip "cd /data/static/10 && cp -r h5_mall h5_mall-${time_stamp}" ssh $ip "cd /data/static/10/h5_mall && /bin/rm -rf *" scp ../static/${h5_mall_zip_name} $ip:/data/static/10/h5_mall/ ssh $ip "cd /data/static/10/h5_mall && unzip ${h5_mall_zip_name}" done fi fi
#这个脚本早上临时做的,发现这个静态资源还没有脚本发布。脚本主要对参数和运行脚本的用户做了判断。
$ cat copy_cms_static.sh #!/bin/bash war=$1 nginx_static_ip=10.10.1.28 temp_time=`date +%Y-%m-%d-%H-%M-%S` if [ `whoami` == "ody" ];then if [ $# -ne "1" ];then echo -n "输入的参数不对,请重新输入." else ssh ${nginx_static_ip} "cd /data/stgds/ && cp -r cms_dev{,-${temp_time}}" ssh ${nginx_static_ip} "cd /data/stgds/cms_dev/ && /bin/rm -rf ./*" scp ../static/${war} ${nginx_static_ip}:/data/stgds/cms_dev/ ssh ${nginx_static_ip} "cd /data/stgds/cms_dev/ && unzip ${war}" fi else echo -n "当前用户不是ody用户." fi
下面是新项目一套发布脚本,昨天改的,运行一天还未见报错、未见发布失败的。
war包发布的脚本:
# cat deploy_new.sh #!/bin/sh read -p "请输入你需要发布的Poll Name:" pool_name if [ "$pool_name" = "" ];then echo "pool_name 不支持为空!" else product_ip_list=`cat ./deploy_env.ini | grep ${pool_name} | awk -F ‘=‘ ‘{print $2}‘` time_stamp=`date +"%Y-%m-%d-%H-%M-%S"` function shutdown_tomcat() { ip=$1 tomcat_port=8080 tomcat_id=`ssh [email protected]$ip ps -ef | grep java | grep "tomcat" | grep -v "grep" | awk ‘{print $2}‘` if [ ! $tomcat_id ];then echo "tomcat process in ${ip} is not exist." else echo "shutdown tomcat in ${ip}" ssh [email protected]$ip "/bin/kill -9 $tomcat_id" if [ $? == 0 ];then echo "shutdown [email protected]$ip tomcat process is success." else echo "shutdown [email protected]$ip tomcat process is false." exit 2 fi fi } function start_tomcat() { ip=$1 echo "start tomcat in ${ip}." ssh [email protected]$ip "JAVA_HOME=/usr/local/java/jdk1.7.0_80;export JAVA_HOME;/bin/sh /data/tomcat/bin/startup.sh" ssh [email protected]$ip "/usr/local/java/jdk1.7.0_80/bin/jps" } if [ `whoami` == "ody" ];then ssh 10.18.3.200 "cd /data/war && md5sum -c ${pool_name}.war.md5" if [ $? -eq 0 ];then pool_ip_list=`awk ‘BEGIN{list="‘${product_ip_list}‘";split(list,ip_list,",");for(ip in ip_list){print ip_list[ip];}}‘` for deploy_ip in ${pool_ip_list[*]};do shutdown_tomcat ${deploy_ip} ssh ${deploy_ip} "cd /data/tomcat/webapps && mv ${pool_name}.war ${pool_name}.war-${time_stamp}" ssh ${deploy_ip} "cd /data/tomcat/webapps && rm -rf ${pool_name}" scp 10.18.3.200:/data/war/${pool_name}.war /data/war/ scp /data/war/${pool_name}.war ${deploy_ip}:/data/tomcat/webapps start_tomcat ${deploy_ip} done else echo "md5 check false." exit 2 fi else echo "please use ody user to exec this shell." fi fi
脚本中的deploy_env.ini文件,是war和ip对应的关系:
大致是下面的样子:
# cat deploy_env.ini ad-whale=10.18.1.1,10.18.1.64 ad-whale-web=10.18.1.2
本文出自 “LINUX Super梦” 博客,请务必保留此出处http://215687833.blog.51cto.com/6724358/1905065
以上是关于Tomcat pool 发布脚本的主要内容,如果未能解决你的问题,请参考以下文章
org.apache.tomcat.jdbc.pool 中的验证查询
org.apache.tomcat.jdbc.pool.jmx.JmxUtil.registerJmx Jmx 注册失败
在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途
使用tomcat jdbc pool StatementCache拦截器时出错
tomcat 7.0.42 pooling, hibernate 4.2, mysql 坚如磐石的自动重新连接解决方案
java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool DataSourceFactory