ossUpgrade ok
This commit is contained in:
parent
dba1a7b717
commit
eb898022f3
@ -12,6 +12,17 @@ ossPath=$5
|
|||||||
|
|
||||||
PATH=PATH:/usr/bin:/usr/sbin
|
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
|
cd $workDirectory
|
||||||
echo "current path: $(pwd)"
|
echo "current path: $(pwd)"
|
||||||
if [ ! -f "$fileName" ];then
|
if [ ! -f "$fileName" ];then
|
||||||
@ -44,10 +55,16 @@ if [ ${oriSum} = ${desSum} ];then
|
|||||||
journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log
|
journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log
|
||||||
${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossPath}autoDeploy.log
|
${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossPath}autoDeploy.log
|
||||||
echo "destination file is same with origin file,no need to replace"
|
echo "destination file is same with origin file,no need to replace"
|
||||||
|
uploadLog
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
||||||
|
@ -50,7 +50,9 @@ if [ ${oriSum} = ${desSum} ];then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cd ~
|
cd ~
|
||||||
unzip $fileName
|
rm dist -fr
|
||||||
|
rm $projectName -fr
|
||||||
|
unzip $fileName -fq
|
||||||
echo "projectName: ${projectName}"
|
echo "projectName: ${projectName}"
|
||||||
mv dist ~/$projectName
|
mv dist ~/$projectName
|
||||||
cd $projectPath
|
cd $projectPath
|
||||||
|
131
ossUpgrade.sh
131
ossUpgrade.sh
@ -1,62 +1,93 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# usage:
|
#usage:
|
||||||
## 这个脚本能正常工作的前提是 systemd脚本如果不是root,也能通过sudo 调用高级权限来执行。
|
|
||||||
## 否则就要结合checkService.sh一起使用。那个单独放在一个服务里,用root用户执行
|
|
||||||
# ./ossUpgrade.sh "stage/ztsjxxxt/frontEnd/" html.zip ztsjxxxt
|
# ./ossUpgrade.sh "stage/ztsjxxxt/frontEnd/" html.zip ztsjxxxt
|
||||||
|
|
||||||
|
PATH=PATH:/usr/bin:/usr/sbin
|
||||||
ossPath=$1 #末尾别忘了加/
|
ossPath=$1 #末尾别忘了加/
|
||||||
fileName=$2
|
fileName=$2
|
||||||
serviceName=$3
|
serviceName=$3
|
||||||
projectName="${fileName%.*}"
|
projectName="${fileName%.*}"
|
||||||
|
|
||||||
PATH=PATH:/usr/bin:/usr/sbin
|
function foundNew(){
|
||||||
cd ~
|
cd ~
|
||||||
./ossutil stat oss://ztupload/${ossPath}$fileName > ${projectName}_oss.info
|
./ossutil stat oss://ztupload/${ossPath}$fileName > ${projectName}_oss.info
|
||||||
ossInfo=$(cat ${projectName}_oss.info)
|
ossInfo=$(cat ${projectName}_oss.info)
|
||||||
out=${ossInfo##*Etag}
|
echo "${fileName} in oss info: "
|
||||||
out=${out%Last*}
|
echo " " $ossInfo
|
||||||
out=${out#*: }
|
out=${ossInfo##*Length}
|
||||||
ossSum=${out,,}
|
out=${out%Content-Md5*}
|
||||||
ossSum="${ossSum% *}"
|
out=${out#*: }
|
||||||
echo "oss md5:"$ossSum
|
ossLength=${out,,}
|
||||||
result=$(echo $ossInfo | grep "error")
|
ossLength="${ossLength% *}"
|
||||||
if [[ "$result" != "" ]]; then
|
ossLength=$(echo $ossLength)
|
||||||
echo $result
|
ossLength="${ossLength%% *}"
|
||||||
exit 0
|
echo "ossLength " "|"${ossLength}"|"
|
||||||
fi
|
result=$(echo $ossInfo | grep "error")
|
||||||
curSum=$(md5sum $fileName)
|
if [[ "$result" != "" ]]; then
|
||||||
curSum="${curSum% *}"
|
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 file,no 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 file,no 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"
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user