ossUpgrade ok

This commit is contained in:
zhangkun9038@dingtalk.com 2022-09-10 08:16:20 +00:00
parent dba1a7b717
commit eb898022f3
3 changed files with 109 additions and 59 deletions

View File

@ -12,6 +12,17 @@ ossPath=$5
PATH=PATH:/usr/bin:/usr/sbin
function uploadLog ()
{
echo "current user is ${USER}"
journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log
${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossPath}autoDeploy.log
if [ $? -ne 0 ]; then
echo "error: upload log to oss failed!"
exit 0
fi
}
cd $workDirectory
echo "current path: $(pwd)"
if [ ! -f "$fileName" ];then
@ -44,10 +55,16 @@ if [ ${oriSum} = ${desSum} ];then
journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log
${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossPath}autoDeploy.log
echo "destination file is same with origin fileno need to replace"
uploadLog
exit 0
fi
systemctl restart $serviceName
sleep 10
journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log
${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossPath}autoDeploy.log
systemctl restart $serviceName
if [ $? -ne 0 ]; then
echo "error: systemctl restart ${serviceName} failed!"
exit 0
fi
echo "ok: systemctl restart ${serviceName} success!"
sleep 10
uploadLog

View File

@ -50,7 +50,9 @@ if [ ${oriSum} = ${desSum} ];then
fi
cd ~
unzip $fileName
rm dist -fr
rm $projectName -fr
unzip $fileName -fq
echo "projectName: ${projectName}"
mv dist ~/$projectName
cd $projectPath

View File

@ -1,62 +1,93 @@
#!/bin/bash
# usage:
## 这个脚本能正常工作的前提是 systemd脚本如果不是root也能通过sudo 调用高级权限来执行。
## 否则就要结合checkService.sh一起使用。那个单独放在一个服务里用root用户执行
#usage:
# ./ossUpgrade.sh "stage/ztsjxxxt/frontEnd/" html.zip ztsjxxxt
PATH=PATH:/usr/bin:/usr/sbin
ossPath=$1 #末尾别忘了加/
fileName=$2
serviceName=$3
projectName="${fileName%.*}"
PATH=PATH:/usr/bin:/usr/sbin
cd ~
./ossutil stat oss://ztupload/${ossPath}$fileName > ${projectName}_oss.info
ossInfo=$(cat ${projectName}_oss.info)
out=${ossInfo##*Etag}
out=${out%Last*}
out=${out#*: }
ossSum=${out,,}
ossSum="${ossSum% *}"
echo "oss md5:"$ossSum
result=$(echo $ossInfo | grep "error")
if [[ "$result" != "" ]]; then
echo $result
exit 0
fi
curSum=$(md5sum $fileName)
curSum="${curSum% *}"
function foundNew(){
cd ~
./ossutil stat oss://ztupload/${ossPath}$fileName > ${projectName}_oss.info
ossInfo=$(cat ${projectName}_oss.info)
echo "${fileName} in oss info: "
echo " " $ossInfo
out=${ossInfo##*Length}
out=${out%Content-Md5*}
out=${out#*: }
ossLength=${out,,}
ossLength="${ossLength% *}"
ossLength=$(echo $ossLength)
ossLength="${ossLength%% *}"
echo "ossLength " "|"${ossLength}"|"
result=$(echo $ossInfo | grep "error")
if [[ "$result" != "" ]]; then
echo $result
exit 0
fi
curLength=$(ls -l ${fileName} | awk '{print $5}')
if [ "${curLength}" = "" ];then
echo "${fileName} not exist, download it"
./ossutil cp oss://ztupload/${ossPath}$fileName ${fileName}
curLength=$(ls -l ${fileName} | awk '{print $5}')
curLength=$(sed -i 's/\n//g' $curLength)
fi
echo "ossLength ${fileName} : "$ossLength
echo "curLength ${fileName} : "$curLength
logPath=${ossPath%/*}
logPath=${logPath%/*}/logs/
osslogPath=oss://ztupload/${logPath}autoDeploy.log
if [ "${ossLength}" = "${curLength}" ];then
return 0
else
return 1
fi
}
function process(){
cd ~
rm $fileName
echo "fileName: " $fileName
./ossutil cp oss://ztupload/${ossPath}${fileName} ${fileName}
}
# function uploadLog(){
# journalctl -n 1000 -xe -t autoDeploy > ~/autoDeploy.log
# if [ $? = 0 ];then
# echo "uploaded log to ${osslogPath}"
# fi
# }
function main(){
echo " "
echo "start ossUpgrade service"
foundNew
result=$?
echo "result $result"
if [ $result = 0 ];then
# uploadLog
echo "local temp file is same with oss fileno need to replace"
exit 0
echo "end ossUpgrade service"
echo " "
else
echo "local temp file $fileName is different from oss, will download..."
fi
process
sleep 10
# uploadLog
echo "replaced"
echo "end ossUpgrade service"
echo " "
}
main
if [ "${curSum}" = "" ];then
./ossutil cp oss://ztupload/${ossPath}$fileName > ${fileName}
curSum=$(md5sum $fileName)
curSum="${curSum% *}"
fi
echo "local file $fileName md5:"$curSum
all=$ossSum
echo "oriMd5: "$all
all=$curSum
echo "curMd5: "$all
logPath=${ossPath%/*}
logPath=${logPath%/*}/logs/
osslogPath=oss://ztupload/${logPath}autoDeploy.log
if [ ${ossSum} = ${curSum} ];then
sudo journalctl -n 1000 -xe -t autoDeploy > ~/autoDeploy.log
./ossutil cp ~/autoDeploy.log ${osslogPath} -f
echo "uploaded log to ${osslogPath}"
echo "destination file is same with oss fileno need to replace"
exit 0
else
echo "local file $fileName is different from oss, will download..."
fi
rm $fileName
echo "fileName: " $fileName
./ossutil cp oss://ztupload/${ossPath}${fileName} ${fileName}
sudo systemctl restart $serviceName
sleep 10
sudo journalctl -n 1000 -xe -t autoDeploy > ~/autoDeploy.log
./ossutil cp ~/autoDeploy.log osslogPath -f
echo "replaced"