博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JENKINS 打包发布脚本
阅读量:4981 次
发布时间:2019-06-12

本文共 4768 字,大约阅读时间需要 15 分钟。

#!/bin/bash#nohup bash check_new_pkgs_dev.sh &#steps below:##发布的机器上运行这个脚本#定时遍历发布包存放路径#1.遍历所有要发布的包#2.对于每一个包,找到这个包的时候,停止相应的服务#3.将deployed下面相应的已发布目录归档到history中#4.将压缩包解压到deployed下面相应的项目目录中#5.将压缩包移到history中归档#6.启动相应服务###注意进程只能启一个,!!!!!##NOTE 发布zjzjc-voting的各个环境,单机版,zjdev环境之外的需要修改各dir从zjdev改到相应的环境##取脚本名字PROGNAME=`basename $0`pacBaseNameArr=(zjzc-web-flow zjzc-web-api zjzc-pay zjzc-web-frontEnd zjzc-web-backoffice zjzc-voting-front zjzc-voting zjzc-wze-proxy zjzc-hy-core zjzc-hy-pre zjzc-hy-admin-pre zjzc-backoffice-sso-server zjzc-hy-front zjzc-hy-web-admin zjzc-message-proxy)serviceNameArr=(tomcat8081 tomcat8082 tomcat8083 no no no tomcat8080 tomcat8084 tomcat8085 tomcat8086 tomcat8087 tomcat8088 no no tomcat8089)tomcatPathKeyword=(8081 8082 8083 no no no 8080 8084 8085 8086 8087 8088 no no 8089)##历史发布目录UPLOAD_DIR=/t/deploy/zjdev/deployableApps##应用部署的目录DEPLOYED_DIR=/t/deploy/zjdev/deployedApps##历史应用目录HISTORY_FOLDER=/t/deploy/zjdev/deployableApps/history/folder##历史的war包HISTORY_WAR=/t/deploy/zjdev/deployableApps/history/warif [ -d "$UPLOAD_DIR" ]then        :else        mkdir -p $UPLOAD_DIRfiif [ -d "$DEPLOYED_DIR" ]then        :else        mkdir -p $DEPLOYED_DIRfiif [ -d "$HISTORY_FOLDER" ]then        :else        mkdir -p $HISTORY_FOLDERfiif [ -d "$HISTORY_WAR" ]then        :else        mkdir -p $HISTORY_WARfi##pacBaseNameArr=(zjzc-web-flow zjzc-web-api zjzc-pay zjzc-web-frontEnd zjzc-web-backoffice zjzc-voting-front zjzc-voting zjzc-wze-proxy zjzc-hy-core zjzc-hy-pre zjzc-hy-admin-pre zjzc-backoffice-sso-server zjzc-hy-front zjzc-hy-web-admin zjzc-message-proxy)##pacBaseNameArr 数组长度appArrLen=${#pacBaseNameArr[*]}while true do		DATETIME=`date +%Y''%m''%d'-'%H''%M''%S`        ### check if there is new war at UPLOAD_DIR ###        #ls -l $UPLOAD_DIR/${APPNAME}*.war >/dev/null 2>&1        #if [ $? -eq "0" ]		        #then			for((i=0;i<"$appArrLen";i=i+1))			do						##UPLOAD_DIR=/t/deploy/zjdev/deployableApps                                UPLOAD_DIR_WAR_COUNT=`ls -l $UPLOAD_DIR | grep -E "${pacBaseNameArr[$i]}.*.(rar|zip|war)$" | wc -l`								                if [ $UPLOAD_DIR_WAR_COUNT -ne "1" ]                then					echo "$DATETIME ${pacBaseNameArr[$i]} has too many pkgs or no pkg, please check it,  now continue! " >>/var/log/${PROGNAME}.out					continue                fi								###no need to restart service for static web								###								##serviceNameArr=(tomcat8081 tomcat8082 tomcat8083 no no no tomcat8080 tomcat8084 tomcat8085 tomcat8086 tomcat8087 tomcat8088 no no tomcat8089)				##静态资源不重启,tomcat重启				if [ ${serviceNameArr[$i]} != "no" ]				then					###stop service					service ${serviceNameArr[$i]} stop										##每个应用的进程					procIds=`ps -ef | grep -E java.*${tomcatPathKeyword[$i]} | awk '{printf $2 " "}'`					procNums=`echo $procIds | wc -w`					if [ $procNums -gt "1" ]					then						echo "service with keyword: ${tomcatPathKeyword[i]} still has process ids: $procIds survived, kill them after 10 seconds"						sleep 10						kill $procIds					fi					echo "service ${serviceNameArr[$i]} stopped"				fi								echo "echo UPLOAD_DIR_WAR_COUNT:$UPLOAD_DIR_WAR_COUNT at $DATETIME for ${pacBaseNameArr[$i]}";								### move current tomcat to HISTORY_FOLDER                  ##DEPLOYED_DIR=/t/deploy/zjdev/deployedApps	                ##移动当前应用目录 到历史目录下HISTORY_FOLDER=/t/deploy/zjdev/deployableApps/history/folder												##HISTORY_FOLDER=/t/deploy/zjdev/deployableApps/history/folder                mv $DEPLOYED_DIR/${pacBaseNameArr[$i]} $HISTORY_FOLDER/${pacBaseNameArr[$i]}_$DATETIME 								##UPLOAD_DIR=/t/deploy/zjdev/deployableApps								##取应用的名字zjzc-web-api-1.1.17.war_20160708-151024                NEW_WAR_NAME=`ls -l $UPLOAD_DIR/${pacBaseNameArr[$i]}*.* | awk -F"/" '{ print $NF }'`                ### unzip new war								##应用目录,判断backoffice,后面添加/backoffice				subfolder="${pacBaseNameArr[$i]}";				if [ ${pacBaseNameArr[$i]} == "zjzc-web-backoffice" ]				then					subfolder="$subfolder/backoffice"				fi								##DEPLOYED_DIR=/t/deploy/zjdev/deployedApps									mkdir -p $DEPLOYED_DIR/$subfolder								##把打包好的包,解压到对应目录                unzip -o $UPLOAD_DIR/$NEW_WAR_NAME -d $DEPLOYED_DIR/$subfolder				                ### mov new war to HISTORY_WAR								##UPLOAD_DIR=/t/deploy/zjdev/deployableApps								##把打包好的包移走到/t/deploy/zjdev/deployableApps/history/war				##HISTORY_WAR=/t/deploy/zjdev/deployableApps/history/war				                mv $UPLOAD_DIR/$NEW_WAR_NAME $HISTORY_WAR/${NEW_WAR_NAME}_$DATETIME				###no need to restart service for static web				if [ ${serviceNameArr[$i]} != "no" ]				then					###start service					service ${serviceNameArr[$i]} start					echo "service started"				fi                			done        #fi				sleep 10done

转载于:https://www.cnblogs.com/zhaoyangjian724/p/6199665.html

你可能感兴趣的文章
【转】Simulink模型架构指导
查看>>
[转载]java开发中的23种设计模式
查看>>
揭秘:黑客必备的Kali Linux是什么,有哪些弊端?
查看>>
linux系统的远程控制方法——学神IT教育
查看>>
springboot+mybatis报错Invalid bound statement (not found)
查看>>
Linux环境下SolrCloud集群环境搭建关键步骤
查看>>
MongoDB的简单使用
查看>>
【noip2004】虫食算——剪枝DFS
查看>>
java小技巧
查看>>
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>
SQL中Group By的使用
查看>>
两个表格中数据不用是一一对应关系--来筛选不同数据,或者相同数据
查看>>
js05-DOM对象二
查看>>
mariadb BINLOG_FORMAT = STATEMENT 异常
查看>>
Java回顾之多线程
查看>>
2018 Multi-University Training Contest 10 - Count
查看>>
HDU6203 ping ping ping
查看>>
Fireworks基本使用
查看>>
Java基础常见英语词汇
查看>>
nginx启动、关闭命令、重启nginx报错open() "/var/run/nginx/nginx.pid" failed
查看>>