From 852c55b51683fae4ef52b84c314bc6f56a2a2893 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Sat, 10 Sep 2022 10:01:00 +0000 Subject: [PATCH] update --- checkService.sh | 107 ++++++++++++++++++++++++++++++------------------ ossUpgrade.sh | 4 +- 2 files changed, 69 insertions(+), 42 deletions(-) diff --git a/checkService.sh b/checkService.sh index 359de24..cbf3c9d 100755 --- a/checkService.sh +++ b/checkService.sh @@ -23,48 +23,75 @@ function uploadLog () fi } -cd $workDirectory -echo "current path: $(pwd)" -if [ ! -f "$fileName" ];then - echo "文件 $fileName 不存在1!" - exit 0 -fi - -oriSum=$(md5sum $fileName) -oriSum="${oriSum% *}" -echo "origin file $fileName md5sum: $oriSum" - -if [ ! -d "$projectPath" ]; then - echo "文件夹 $prjectPath 不存在!" - exit 0 -fi - -cd $projectPath -desSum="" -if [ ! -f "$fileName" ];then - cp ~/$fileName . - exit 0 -else - desSum=$(md5sum $fileName) - desSum="${desSum% *}" +function compare(){ + cd $workDirectory echo "current path: $(pwd)" - echo "destination file ${fileName} md5sum: ${desSum}" -fi + if [ ! -f "$fileName" ];then + echo "文件 $fileName 不存在1!" + return -1 + fi -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 file,no need to replace" + oriSum=$(md5sum $fileName) + oriSum="${oriSum% *}" + echo "origin local temp file $fileName md5sum: |${oriSum}|" + + if [ ! -d "$projectPath" ]; then + echo "文件夹 $prjectPath 不存在!" + return -1 + fi + + cd $projectPath + desSum="" + if [ ! -f "$fileName" ];then + cp ~/$fileName . + return 0 + else + desSum=$(md5sum $fileName) + desSum="${desSum% *}" + echo "current path: $(pwd)" + echo "locfile in projectPath ${fileName} md5sum: |${desSum}|" + fi + + if [ ${oriSum} = ${desSum} ];then + #journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log + return 0 + else + return 1 + fi +} + +function restart(){ + systemctl restart $serviceName + if [ $? -ne 0 ]; then + echo "error: systemctl restart ${serviceName} failed!" + exit 0 + fi + echo "ok: systemctl restart ${serviceName} success!" +} + +function main(){ + echo " " + echo "start checkService service" + compare + result=$? + echo "result $result" + if [ $result = 0 ];then + # uploadLog + echo "local temp file is same with oss file,no need to replace" + echo "ok: checkService done" + echo " " + exit 0 + elif [ $result = 1 ]; then + echo "local temp file $fileName is different from oss, will download..." + else + exit 0 + fi + restart + sleep 10 uploadLog + echo "ok: checkService done" + echo " " exit 0 -fi +} -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 +main diff --git a/ossUpgrade.sh b/ossUpgrade.sh index 4a00d03..73deda3 100755 --- a/ossUpgrade.sh +++ b/ossUpgrade.sh @@ -8,7 +8,7 @@ fileName=$2 serviceName=$3 projectName="${fileName%.*}" -function foundNew(){ +function compare(){ cd ~ ./ossutil stat oss://ztupload/${ossPath}$fileName > ${projectName}_oss.info ossInfo=$(cat ${projectName}_oss.info) @@ -64,7 +64,7 @@ function process(){ function main(){ echo " " echo "start ossUpgrade service" - foundNew + compare result=$? echo "result $result" if [ $result = 0 ];then