标签:增加 term des appname 日期 dep 就是 desc 潜水
鉴于肺活量有限,在潜水了半年多之后上岸来透透气觉着是时候写点东西了,能力有限都是记录平常工作中遇到的问题以及解决方法,如果再能帮到有相似问题的同仁,那就算是额外收获了!【抱拳】#!/bin/bash
#
# SCRIPTNAME:sdwan_version.sh
# DATE: 2020/03/13
# author: Mright
# version: V1.3
# desc:
# V1.2:增加version.info文件到应用用户目录下,保存即将部署的应用版本号以及当前生产上部署的
# 版本号,应用部署完成后将版本号回写到version.info中
# V1.3:调整version.info内容可记录不同应用版本号,记录升级后的版本以及上一个版本号
#
# ******************** DEFINE INPUT BEGIN **********************************
set -o pipefail
\# VERSION:即将部署的版本名
VERSION=$1
\# 即将部署生产版本号
V=$2
V=${V:=$(date +"%Y%m%d")}
\# 版本机上的tar包
VERSIONPACKAGE=$3
# ******************** DEFINE INPUT END **********************************
# ******************** DEFINE ARGS BEGIN *********************************
# 版本信息
APPINFOFILE="${HOME}/version.info"
# 当前应用版本号
CURRENTVERSIONID=$(cat ${APPINFOFILE}|grep "${VERSION}_latest"|awk -F‘:‘ ‘{print $2}‘)
# 网关应用名
ZUULAPPNAME="example-sdwan-api-gateway-${CURRENTVERSIONID}.jar"
# SITE应用名
SITEAPPNAME="example-sdwan-nw-site-${CURRENTVERSIONID}.jar"
# DEVICE应用名
DEVICEAPPNAME="example-sdwan-nw-device-${CURRENTVERSIONID}.jar"
# WEB应用名
WEBAPPNAME="example-web-dist"
# 网关部署路径
ZUULAPPPATH="${HOME}/exampleb-sdwan-api-gateway/"
# SITE部署路径
SITEAPPPATH="${HOME}/example-sdwan-nw-site/"
# DEVICE部署路径
DEVICEAPPPATH="${HOME}/example-sdwan-nw-device/"
# WEB前端部署路径
WEBAPPPATH="${HOME}/web/"
# VERSONDATE:版本部署日期
VERSIONDATE=$(date +"%Y%m%d")
BASEVERSIONPATH="/home/example/nas/sdwan"
# VERSIONPATH:版本下载存放路径
VERSIONPATH="${BASEVERSIONPATH}/sdwan_version/${VERSIONDATE}"
# DBVERSIONPATH:版本数据库sql脚本备份存放路径
DBVERSIONPATH="${BASEVERSIONPATH}/db_version/${VERSIONDATE}"
# ZUULVERSIONPATH:网关微服务备份路径
ZUULVERSIONPATH="${BASEVERSIONPATH}/zuul_version/${VERSIONDATE}"
# SITEVERSIONPATH:site微服务备份路径
SITEVERSIONPATH="${BASEVERSIONPATH}/site_version/${VERSIONDATE}"
# DEVICEVERSIONPATH:device微服务备份路径
DEVICEVERSIONPATH="${BASEVERSIONPATH}/device_version/${VERSIONDATE}"
# WEBVERSIONPATH: web前端备份路径
WEBVERSIONPATH="${BASEVERSIONPATH}/web_version/${VERSIONDATE}"
# 脚本执行日志存放路径
LOGPATH="/tmp/${HOSTNAME}_${VERSIONDATE}.log"
# ******************** DEFINE ARGS END ***********************************
# ******************** FUNCTION func_info BEGIN **************************
function func_info(){
cat<<EOF
******************脚本执行方法*****************
sh sdwan_version.sh <args1><args2><args3>
参数说明:
args1:部署应用名称,写参数时需去掉"<"">"
[zuul|site|device|web]
args2:即将部署应用版本号
1.3.0
args3:版本机上的版本包tar包全名
upline-file-v1.3.tar.gz
示例:sh sdwan_version.sh zuul 1.3.0 upline-file-v1.3.tar.gz
EOF
}
# ******************** FUNCTION func_info END ***************************
# ******************** FUNCTION log_info BEGIN **************************
function log_info(){
echo "[$(date +‘%Y-%m-%d %H:%M:%S‘)][INFO]"
}
# ******************** FUNCTION log_info END ***************************
# ******************** FUNCTION log_info BEGIN **************************
function log_error(){
echo "[$(date +‘%Y-%m-%d %H:%M:%S‘)][ERROR]"
}
# ******************** FUNCTION log_info END ***************************
# ******************** FUNCTION init_env BEGIN ***************************
function init_env(){
echo "VERSION=${VERSION},v=${V},VERSIONPACKAGE=${VERSIONPACKAGE}"
echo "$(log_info)准备初始化环境..."
if [ ! -s ${APPINFOFILE} ];then
echo -ne "zuul_last_id: 1.1.0\nzuul_temporary_id:1.1.0\nzuul_latest_id:1.1.0\n" >>${APPINFOFILE}
echo -ne "site_last_id: 1.1.0\nsite_temporary_id:1.1.0\nsite_latest_id:1.1.0\n" >>${APPINFOFILE}
echo -ne "device_last_id: 1.1.0\ndevice_temporary_id:1.1.0\ndevice_latest_id:1.1.0\n" >>${APPINFOFILE}
echo -ne "web_last_id: 1.1.0\nweb_temporary_id:1.1.0\nweb_latest_id:1.1.0\n" >>${APPINFOFILE}
fi
[ ! -f ${APPINFOFILE} ]&&{ echo "$(log_error)${APPINFOFILE}不存在";exit 110;}
[ -z "${CURRENTVERSIONID}" ]&&{ echo "$(log_error)未获取到当前应用的版本号!";exit 110;}
[ ! -d ${VERSIONPATH} ]&&{ echo "$(log_info)${VERSIONPATH}不存在准备创建...";mkdir -p ${VERSIONPATH};}
[ ! -d ${DBVERSIONPATH} ]&&{ echo "$(log_info)${DBVERSIONPATH}不存在准备创建...";mkdir -p ${DBVERSIONPATH};}
case ${VERSION} in
"zuul")
[ ! -d ${ZUULVERSIONPATH} ]&&{ echo "$(log_info)${ZUULVERSIONPATH}不存在准备创建...";mkdir -p ${ZUULVERSIONPATH};}
;;
"site")
[ ! -d ${SITEVERSIONPATH} ]&&{ echo "$(log_info)${SITEVERSIONPATH}不存在准备创建...";mkdir -p ${SITEVERSIONPATH};}
;;
"device")
[ ! -d ${DEVICEVERSIONPATH} ]&&{ echo "$(log_info)${DEVICEVERSIONPATH}不存在准备创建...";mkdir -p ${DEVICEVERSIONPATH};}
;;
"web")
[ ! -d ${WEBVERSIONPATH} ]&&{ echo "$(log_info)${WEBVERSIONPATH}不存在准备创建...";mkdir -p ${WEBVERSIONPATH};}
;;
*)
echo "$(log_error)参数错误,请重新输入要操作版本"
exit 110
;;
esac
}
# ******************** FUNCTION init_env END *******************************
# ******************** FUNCTION backup_app BEGIN ***************************
function backup_app(){
echo "${log_info}准备应用备份..."
case ${VERSION} in
"zuul")
# 当前应用版本号
CURRENTVERSIONID=$(cat ${APPINFOFILE}|grep "zuul_latest"|awk -F‘:‘ ‘{print $2}‘)
# 网关应用名
ZUULAPPNAME="example-sdwan-api-gateway-${CURRENTVERSIONID}.jar"
cd ${ZUULVERSIONPATH}
if [ ! -f ${ZUULAPPNAME} ];then
[ ! -f ${ZUULAPPPATH}/${ZUULAPPNAME} ]&&{ echo "$(log_error)${ZUULAPPNAME}不存在无法备份";exit 120;}
cp -a ${ZUULAPPPATH}/${ZUULAPPNAME} ${ZUULVERSIONPATH}
[ $? -eq 0 ]&&{ echo "$(log_info)${ZUULAPPNAME}备份成功";}||{ echo "$(log_error)${ZUULAPPNAME}备份失败!";exit 120;}
# 备份成功将当前生产版本号保存至temporary_id
sed -i "s/zuul_temporary_id:.*/zuul_temporary_id:${V}/g" ${APPINFOFILE}
else
echo "$(log_info)${ZUULAPPNAME}备份已存在无需备份!"
fi
;;
"site")
# 当前应用版本号
CURRENTVERSIONID=$(cat ${APPINFOFILE}|grep "site_latest"|awk -F‘:‘ ‘{print $2}‘)
# SITE应用名
SITEAPPNAME="example-sdwan-nw-site-${CURRENTVERSIONID}.jar"
cd ${SITEVERSIONPATH}
if [ ! -f ${SITEAPPNAME} ];then
[ ! -f ${SITEAPPPATH}/${SITEAPPNAME} ]&&{ echo "$(log_error)${SITEAPPNAME}不存在无法备份";exit 130;}
cp -a ${SITEAPPPATH}/${SITEAPPNAME} ${SITEVERSIONPATH} &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)${SITEAPPNAME}备份成功";}||{ echo "$(log_error)${SITEAPPNAME}备份失败!";exit 130;}
# 备份成功将当前生产版本号保存至temporary_id
sed -i "s/site_temporary_id:.*/site_temporary_id:${V}/g" ${APPINFOFILE}
else
echo "$(log_info)${SITEAPPNAME}备份已存在无需备份!"
fi
;;
"device")
# 当前应用版本号
CURRENTVERSIONID=$(cat ${APPINFOFILE}|grep "device_latest"|awk -F‘:‘ ‘{print $2}‘)
# DEVICE应用名
DEVICEAPPNAME="example-sdwan-nw-device-${CURRENTVERSIONID}.jar"
cd ${DEVICEVERSIONPATH}
if [ ! -f ${DEVICEAPPNAME} ];then
[ ! -f ${DEVICEAPPPATH}/${DEVICEAPPNAME} ]&&{ echo "$(log_error)${DEVICEAPPNAME}不存在无法备份";exit 140;}
cp -a ${DEVICEAPPPATH}/${DEVICEAPPNAME} ${DEVICEVERSIONPATH} &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)${DEVICEAPPNAME}备份成功";}||{ echo "$(log_error){DEVICEAPPNAME}备份失败!";exit 140;}
# 备份成功将当前生产版本号保存至temporary_id
sed -i "s/device_temporary_id:.*/device_temporary_id:${V}/g" ${APPINFOFILE}
else
echo "$(log_info)${DEVICEAPPNAME}备份已存在无需备份!"
fi
;;
"web")
# 当前应用版本号
CURRENTVERSIONID=$(cat ${APPINFOFILE}|grep "web_latest"|awk -F‘:‘ ‘{print $2}‘)
# WEB应用名
WEBAPPNAME="example-web-dist"
cd ${WEBVERSIONPATH}
if [ ! -f ${WEBAPPNAME}.tar.v${CURRENTVERSIONID}.gz ];then
[ ! -d ${WEBAPPPATH}/${WEBAPPNAME} ]&&{ echo "$(log_error)${WEBAPPNAME}不存在无法备份";exit 150;}
tar -zcf ${WEBAPPNAME}.tar.v${CURRENTVERSIONID}.gz -C ${WEBAPPPATH} ${WEBAPPNAME}
# 二次备份,稳定后可取消
if [ -d ${WEBAPPPATH}/${WEBAPPNAME}_$(date +"%Y%m%d").bak ];then
rm -rf ${WEBAPPPATH}/${WEBAPPNAME}_$(date +"%Y%m%d").bak
fi
mv ${WEBAPPPATH}/${WEBAPPNAME} ${WEBAPPPATH}/${WEBAPPNAME}_$(date +"%Y%m%d").bak
[ $? -eq 0 ]&&{ echo "$(log_info)${WEBAPPNAME}备份成功";}||{ echo "$(log_error)${WEBAPPNAME}备份失败!";exit 150;}
# 备份成功将当前生产版本号保存至temporary_id
sed -i "s/web_temporary_id:.*/web_temporary_id:${V}/g" ${APPINFOFILE}
else
echo "$(log_info)${WEBAPPNAME}备份已存在无需备份!"
fi
;;
*)
echo "$(log_error)参数错误,请重新输入要操作版本"
exit 120
;;
esac
}
# ******************** FUNCTION backup_app END *****************************
# ******************** FUNCTION deploy_app BEGIN ***************************
function deploy_app(){
cd ${VERSIONPATH}
# 通过版本tar包获取目录名
LOCALDIR=$(echo ${VERSIONPACKAGE}|awk -F ‘.tar‘ ‘{print $1}‘)
[ ! -f ${VERSIONPACKAGE} ]&&{ echo "$(log_error)版本包不存在,请检查版本包是否已放置在指定位置";exit 200;}
tar -zxf ${VERSIONPACKAGE} &>/dev/null
[ $? -ne 0 ]&&{ echo "$(log_error)版本包解压异常";exit 200;}
cd ${LOCALDIR}
case ${VERSION} in
"zuul")
JAR=$(basename ${ZUULAPPPATH})
[ ! -f ${JAR}-${V}.jar ]&&{ echo "$(log_error)${JAR}-${V}.jar应用jar包不存在,无法部署!";exit 210;}
mv ${JAR}-${V}.jar ${ZUULAPPPATH} &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)网关部署成功!";}||{ echo "$(log_error)网关部署失败!";exit 210;}
sed -i "s/zuul_latest_id:.*/zuul_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/zuul_last_id:.*/zuul_last_id:${CURRENTVERSIONID}/g" ${APPINFOFILE}
;;
"site")
JAR=$(basename ${SITEAPPPATH})
[ ! -f ${JAR}-${V}.jar ]&&{ echo "$(log_error)${JAR}-${V}.jar应用jar包不存在,无法部署!";exit 220;}
mv ${JAR}-${V}.jar ${SITEAPPPATH} &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)SITE微服务部署成功!";}||{ echo "$(log_error)SITE微服务部署失败!";exit 220;}
sed -i "s/site_latest_id:.*/site_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/site_last_id:.*/site_last_id:${CURRENTVERSIONID}/g" ${APPINFOFILE}
;;
"device")
JAR=$(basename ${DEVICEAPPPATH})
[ ! -f ${JAR}-${V}.jar ]&&{ echo "$(log_error)${JAR}-${V}.jar应用jar包不存在,无法部署!";exit 230;}
mv ${JAR}-${V}.jar ${DEVICEAPPPATH} &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)DEVICE微服务部署成功!";}||{ echo "$(log_error)DEVICE微服务部署失败!";exit 230;}
sed -i "s/device_latest_id:.*/device_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/device_last_id:.*/devicd_last_id:${CURRENTVERSIONID}/g" ${APPINFOFILE}
;;
"web")
[ ! -f ${WEBAPPNAME}*.gz ]&&{ echo "${WEBAPPNAME}应用版本包不存在";exit 240;}
tar -zxf ${WEBAPPNAME}*.gz -C ${WEBAPPPATH} &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)前端应用部署成功!";}||{ echo "$(log_error)前端应用部署失败!";exit 240;}
sed -i "s/web_latest_id:.*/web_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/web_last_id:.*/web_last_id:${CURRENTVERSIONID}/g" ${APPINFOFILE}
;;
*)
echo "$(log_error)参数错误,请重新输入要操作版本"
func_info
exit 111
;;
esac
}
#******************** FUNCTION deploy_app END *****************************
function main(){
case ${VERSION} in
"zuul")
init_env
backup_app
deploy_app
;;
"site")
init_env
backup_app
deploy_app
;;
"device")
init_env
backup_app
deploy_app
;;
"web")
init_env
backup_app
deploy_app
;;
*)
echo "$(log_error)参数错误,请重新输入要操作版本"
func_info
exit 111
;;
esac
}
if [ ${#} -ne 3 ];then
echo "参数个数错误"
func_info
exit 100
fi
main
下边给出回滚的脚本
#!/bin/bash
#
# SCRIPTNAME:sdwan_version_rollback.sh
# DATE: 2020/03/12
# author: Mright
# version: V1.2
# desc:
# V1.1:sdwan版本回滚脚本,通过传入操作的应用名称以及要回退至输入的应用版本号,将当前应用进行回退
#
# V1.2:扩展version.info文件内容,根据不同应用记录各应用的版本号,并修改相关处理脚本
#
# ******************** DEFINE INPUT BEGIN **********************************
set -o pipefail
# 版本信息
APPINFOFILE="${HOME}/version.info"
# VERSION:即将部署的版本名
VERSION=$1
# 要回滚版本号
V=$2
#V=${V:=${ROLLBACKVERSION}}
# 版本机上的tar包
#VERSIONPACKAGE=$3
# ******************** DEFINE INPUT END **********************************
# ******************** DEFINE ARGS BEGIN *********************************
APPINFOFILE="${HOME}/version.info"
# 网关应用名
ZUULAPPNAME="example-sdwan-api-zuul-${V}.jar"
# SITE应用名
SITEAPPNAME="example-sdwan-nw-site-${V}.jar"
# DEVICE应用名
DEVICEAPPNAME="example-sdwan-nw-device-${V}.jar"
# WEB应用名
WEBAPPNAME="example-web-dist.tar.v${V}.gz"
# 网关部署路径
ZUULAPPPATH="${HOME}/example-sdwan-api-zuul/"
# SITE部署路径
SITEAPPPATH="${HOME}/example-sdwan-nw-site/"
# DEVICE部署路径
DEVICEAPPPATH="${HOME}/example-sdwan-nw-device/"
# WEB前端部署路径
WEBAPPPATH="${HOME}/web/"
BASEVERSIONPATH="/home/example/nas/sdwan"
# VERSONDATE:版本部署日期
VERSIONDATE=$(date +"%Y%m%d")
# VERSIONPATH:版本下载存放路径
VERSIONPATH="${BASEVERSIONPATH}/sdwan_version/${VERSIONDATE}"
# DBVERSIONPATH:版本数据库sql脚本备份存放路径
DBVERSIONPATH="${BASEVERSIONPATH}/db_version/${VERSIONDATE}"
# ZUULVERSIONPATH:网关微服务备份路径
ZUULVERSIONPATH=$(find ${BASEVERSIONPATH}/zuul_version/ -name "${ZUULAPPNAME}"|tail -1|xargs -r dirname)
# SITEVERSIONPATH:site微服务备份路径
SITEVERSIONPATH=$(find ${BASEVERSIONPATH}/site_version/ -name "${SITEAPPNAME}"|tail -1|xargs -r dirname)
# DEVICEVERSIONPATH:device微服务备份路径
DEVICEVERSIONPATH=$(find ${BASEVERSIONPATH}/device_version/ -name "${DEVICEAPPNAME}"|tail -1|xargs -r dirname)
# WEBVERSIONPATH: web前端备份路径
WEBVERSIONPATH=$(find ${BASEVERSIONPATH}/web_version/ -name "${WEBAPPNAME}"|tail -1|xargs -r dirname)
# 脚本执行日志存放路径
LOGPATH="/tmp/${HOSTNAME}_${VERSIONDATE}.log"
# ******************** DEFINE ARGS END ***********************************
# ******************** FUNCTION func_info BEGIN **************************
function func_info(){
cat<<EOF
******************脚本执行方法*****************
sh sdwan_version.sh <args1><args2>
参数说明:
args1:回滚应用名称,写参数时需去掉"<"">"
[zuul|site|device|web]
args2:要回滚的当前版本号
1.1.0
示例:sh sdwan_version_rollback.sh zuul 1.1.0
EOF
}
# ******************** FUNCTION func_info END ***************************
# ******************** FUNCTION log_info BEGIN **************************
function log_info(){
echo "[$(date +‘%Y-%m-%d %H:%M:%S‘)][INFO]"
}
# ******************** FUNCTION log_info END ***************************
# ******************** FUNCTION log_info BEGIN **************************
function log_error(){
echo "[$(date +‘%Y-%m-%d %H:%M:%S‘)][ERROR]"
}
# ******************** FUNCTION log_info END ***************************
# ******************** FUNCTION rollback_app BEGIN *************************
function rollback_app(){
[ ! -f ${APPINFOFILE} ]&&{ echo "$(log_error)${APPINFOFILE}不存在";exit 110;}
case ${VERSION} in
"zuul")
CURRENTVERSION=$(cat ${APPINFOFILE}|grep "zuul_latest"|awk -F ‘:‘ ‘{print $2}‘)
ROLLBACKVERSION=$(cat ${APPINFOFILE}|grep "zuul_latest"|awk -F ‘:‘ ‘{print $2}‘)
[ "${V}" == "${CURRENTVERSION}" ]&&{ echo "$(log_info)要恢复版本号与当前版本号相同,无需恢复"&& exit 0;}
cd ${ZUULVERSIONPATH}
if [ -f ${ZUULAPPNAME} ];then
CURRENTVERSIONNAME=$(echo ${ZUULAPPNAME}|sed -r "s/([0-9.]*)jar/${CURRENTVERSION}.jar/g")
rm -f ${ZUULAPPPATH}/${CURRENTVERSIONNAME}
cp -a ${ZUULVERSIONPATH}/${ZUULAPPNAME} ${ZUULAPPPATH}/ &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)回滚成功!";}||{ echo "$(log_error)回滚失败!";exit 500;}
sed -i "s/zuul_latest_id:.*/zuul_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/zuul_last_id:.*/zuul_last_id:${CURRENTVERSION}/g" ${APPINFOFILE}
else
echo "$(log_error)${ZUULAPPNAME}不存在,无法回滚!"
exit 500
fi
;;
"site")
CURRENTVERSION=$(cat ${APPINFOFILE}|grep "site_latest"|awk -F ‘:‘ ‘{print $2}‘)
ROLLBACKVERSION=$(cat ${APPINFOFILE}|grep "site_latest"|awk -F ‘:‘ ‘{print $2}‘)
[ "${V}" == "${CURRENTVERSION}" ]&&{ echo "$(log_info)要恢复版本号与当前版本号相同,无需恢复"&& exit 0;}
cd ${SITEVERSIONPATH}
if [ -f ${SITEAPPNAME} ];then
CURRENTVERSIONNAME=$(echo ${SITEAPPNAME}|sed -r "s/([0-9.]*)jar/${CURRENTVERSION}.jar/g")
rm -f ${SITEAPPPATH}/${CURRENTVERSIONNAME}
cp -a ${SITEVERSIONPATH}/${SITEAPPNAME} ${SITEAPPPATH}/ &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)回滚成功!";}||{ echo "$(log_error)回滚失败!";exit 500;}
sed -i "s/site_latest_id:.*/site_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/site_last_id:.*/site_last_id:${CURRENTVERSION}/g" ${APPINFOFILE}
else
echo "$(log_error)${SITEAPPNAME}不存在,无法回滚!"
exit 500
fi
;;
"device")
CURRENTVERSION=$(cat ${APPINFOFILE}|grep "device_latest"|awk -F ‘:‘ ‘{print $2}‘)
ROLLBACKVERSION=$(cat ${APPINFOFILE}|grep "device_latest"|awk -F ‘:‘ ‘{print $2}‘)
[ "${V}" == "${CURRENTVERSION}" ]&&{ echo "$(log_info)要恢复版本号与当前版本号相同,无需恢复"&& exit 0;}
cd ${DEVICEVERSIONPATH}
if [ -f ${DEVICEAPPNAME} ];then
CURRENTVERSIONNAME=$(echo ${DEVICEAPPNAME}|sed -r "s/([0-9.]*)jar/${CURRENTVERSION}.jar/g")
rm -f ${DEVICEAPPPATH}/${CURRENTVERSIONNAME}
cp -a ${DEVICEVERSIONPATH}/${DEVICEAPPNAME} ${DEVICEAPPPATH}/ &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)回滚成功!";}||{ echo "$(log_error)回滚失败!";exit 500;}
sed -i "s/device_latest_id:.*/device_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/device_last_id:.*/device_last_id:${CURRENTVERSION}/g" ${APPINFOFILE}
else
echo "$(log_error)${DEVICEAPPNAME}不存在,无法回滚!"
exit 500
fi
;;
"web")
CURRENTVERSION=$(cat ${APPINFOFILE}|grep "web_latest"|awk -F ‘:‘ ‘{print $2}‘)
ROLLBACKVERSION=$(cat ${APPINFOFILE}|grep "web_latest"|awk -F ‘:‘ ‘{print $2}‘)
[ "${V}" == "${CURRENTVERSION}" ]&&{ echo "$(log_info)要恢复版本号与当前版本号相同,无需恢复"&& exit 0;}
cd ${WEBVERSIONPATH}
if [ -f ${WEBAPPNAME} ];then
CURRENTVERSIONNAME=$(echo ${WEBAPPNAME}|cut -d ‘.‘ -f1)
rm -rf ${WEBAPPPATH}/${CURRENTVERSIONNAME}
tar -zxf ${WEBVERSIONPATH}/${WEBAPPNAME} -C ${WEBAPPPATH} &>/dev/null
[ $? -eq 0 ]&&{ echo "$(log_info)回滚成功!";}||{ echo "$(log_error)回滚失败!";exit 500;}
sed -i "s/web_latest_id:.*/web_latest_id:${V}/g" ${APPINFOFILE}
# 部署成功将当前生产版本号保存至temporary_id
sed -i "s/web_last_id:.*/web_last_id:${CURRENTVERSION}/g" ${APPINFOFILE}
else
echo "$(log_error)${WEBAPPNAME}不存在,无法回滚!"
exit 500
fi
;;
*)
echo "$(log_error)参数错误,请重新输入要操作版本"
func_info
exit 111
;;
esac
}
# ******************** FUNCTION rollback_app END ***************************
if [ ${#} -ne 2 ];then
echo "参数个数错误"
func_info
exit 100
fi
rollback_app
看着内容挺唬人一大堆,其实就是判断多一些,好多的代码都是重复的,涉及到一台服务器要部署多个微服务所以代码还是有很大优化空间的,在这就不多做叙述了。
最后吐槽一下cto的markdown编辑器,头一次接触太难用了编辑让人抓狂!
标签:增加 term des appname 日期 dep 就是 desc 潜水
原文地址:https://blog.51cto.com/goodjoe/2478513