pjb fabu
#!/bin/bash PyPath=/opt/shell/mysql LocaName=`pwd` bagname=`basename $LocaName` sleep 1s ConfList=`python /opt/shell/mysql/select.py $bagname` #远程同步ip组 IpList=`echo $ConfList|awk -F ',' '{print $5}'` echo "远程ip:$IpList" #本地包路径 BasePath=`echo $ConfList|awk -F ',' '{print $1}'` echo "本地包路径:$BasePath" DirName=$BasePath/bak/`date +%Y%m%d` PagTime=`date +%Y%m%d%H%M` #本地包名称 fbagname=`ls $BasePath/package` fpath=$BasePath/package/$fbagname echo $fbagname #本地配置文件路径 ConfName=`ls $BasePath/conf` CBasePath=$BasePath/conf/$ConfName #远程执行脚本路径 ShPath=`echo $ConfList|awk -F ',' '{print $4}'` ShName=`basename $ShPath` ShWath=`dirname $ShPath` #远程包路径 ForPath=`echo $ConfList|awk -F ',' '{print $2}'` ConfForPath=$ForPath/conf #微信通知: function f_weixin() { Tstatus=$2 #0为开始发布,1为完成发布 Ttempip=$1 BakName=$DirName/"$bagname"_$PagTime.tar.gz if [ $Tstatus -eq 0 ] ; then msg="服务器$Ttempip:$bagname服务开始发布.." /usr/bin/curl http://172.16.3.50/zabbix_web/weixin/weixin.php?msg="$msg" sleep 1s #发布开始状态写入数据库 python $PyPath/insert.py $bagname $Ttempip $BakName else msg="服务器$Ttempip:$bagname服务完成发布.." /usr/bin/curl http://172.16.3.50/zabbix_web/weixin/weixin.php?msg="$msg" sleep 1 #发布完成写入数据库 python $PyPath/update.py $bagname sleep 1s Date2=`date "+%Y-%m-%d %H:%M:%S"` echo "$Date2 $Ttempip static重启更新版本完成" |tee $LogFile echo "==============================================================" |tee $LogFile fi } #备份前一个版本 function f_bakstatic() { if [ ! -d "$DirName" ]; then mkdir $DirName fi cd /data/online/static echo "开始备份程序包.." sleep 2s tar -C $BasePath -zcvf $DirName/$bagname_$PagTime.tar.gz package echo "备份已经完成,备份包:$DirName/$bagname_$PagTime.tar.gz.." echo "......................................................." echo "......................................................." echo "......................................................." sleep 1s } #同步文件到远程服务器 function static_rs() { echo "开始更新程序包到同步目录$BasePath/package.." sleep 1s rsync -avz -L --progress --delete --port=3878 $BasePath/temp/ $BasePath/package/ echo "更新程序包完成.." echo "......................................................." echo "......................................................." echo "......................................................." sleep 1s OnlineIp=$1 echo "开始同步脚本到远程服务器执行" ansible $OnlineIp -m copy -a "src=$ShPath dest=$ShWath owner=www group=www mode=0755" sleep 3s echo "开始同步新包到远程服务器" ansible $OnlineIp -m copy -a "src=$fpath dest=$ForPath owner=www group=www mode=0755" echo "开始执行远程生产服务器:$OnlineIp" 重启服务脚本 ansible $OnlineIp -m shell -a $ShPath sleep 2s echo "同步脚本到生产环境服务器:$OnlineIp完成.." echo "......................................................." echo "......................................................." echo "......................................................." sleep 1s } function f_fabu() { read -p "请选择是否需要替换配置文件, 1为替换;2为不替换:" ti #备份程序 f_bakstatic; #微信提示 for OnIp in $IpList do #是否更新配置文件 if [ "$ti" == 1 ]; then echo " 开始同步配置文件到远程服务器" echo $CBasePath echo $ForPath ansible $OnIp -m copy -a "src=$CBasePath dest=$ConfForPath owner=www group=www mode=0755" fi f_weixin $OnIp 0 sleep 2s static_rs $OnIp sleep 2s f_weixin $OnIp 1 done } f_fabu;