aws 零停機部署腳本

腳本

#!/bin/bash

logdir="/var/log/deploy"
logfile="$logdir/qa.log"
if [ ! -d "$logdir" ]; then
  mkdir $logdir
fi

targetGroup="arn:aws:elasticloadbalancing:xxx"
targets="Id=i-xxx,Port=xxx"



echo "####### start #######" | tee -a $logfile
echo "####### $(date '+%Y-%m-%d %H:%M:%S') #######" | tee -a $logfile


echo "1> $(date '+%Y-%m-%d %H:%M:%S'): unregister" | tee -a $logfile
aws elbv2 deregister-targets \
  --target-group-arn $targetGroup \
  --targets  $targets \
  --output text | tee -a $logfile


echo "2> $(date '+%Y-%m-%d %H:%M:%S'): sleep 30" | tee -a $logfile
sleep 30


echo "3> $(date '+%Y-%m-%d %H:%M:%S'): deploy" | tee -a $logfile
systemctl stop xxxx
cp /Library/JP-qa/xxxx.tmp /Library/JP-qa/xxxx.jar 2>&1
systemctl start xxxx


echo "4> $(date '+%Y-%m-%d %H:%M:%S'): register" | tee -a $logfile
aws elbv2 register-targets \
  --target-group-arn $targetGroup \
  --targets  $targets \
  --output text | tee -a $logfile


echo "####### $(date '+%Y-%m-%d %H:%M:%S') #######" | tee -a $logfile
echo "####### done #######" | tee -a $logfile
echo | tee -a $logfile
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章