腳本
#!/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