ready to go

This commit is contained in:
zhangkun9038@dingtalk.com 2022-09-10 18:06:13 +00:00
parent 291a3e314b
commit 45e9349fd0
3 changed files with 136 additions and 81 deletions

@ -3,6 +3,7 @@ fileName=$1
projectPath=$2
PATH=PATH:/usr/bin:/usr/sbin
sleep 15
cd ~
echo "current path: $(pwd)"
if [ ! -f "$fileName" ];then

@ -1,30 +1,36 @@
#!/bin/bash
## Usage
# 如果虚机上的shell里面不能执行sudu这个脚本就能派上用场在root用户下执行此脚本也就绕过sudo限制了
## ./checkService.sh ztsjxxxt.jar "/usr/local/jar" ztsjxxxt "/home/ubuntu/" "production/investigate/backEnd/"
## ./checkService.sh ztsjxxxt.jar "/usr/local/jar" ztsjxxxt "/home/ubuntu" "production/investigate/backEnd"
fileName=$1
projectPath=$2
serviceName=$3
workDirectory=$4
workPath=$4
ossLogPath=$5
PATH=PATH:/usr/bin:/usr/sbin
function uploadLog ()
function uploadLog()
{
ctype=$1
identify=$2
count=$3
echo "current user is ${USER}"
journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log
${workDirectory}ossutil cp ${workDirectory}autoDeploy.log oss://ztupload/${ossLogPath}autoDeploy.log
if [ $? -ne 0 ]; then
echo "error: upload log to oss failed!"
exit 0
journalctl -n $count -xe -${ctype} $identify > ${workPath}/${identify}.log
${workPath}/ossutil cp -f ${workPath}/${identify}.log oss://ztupload/${ossLogPath}/logs/${identify}.log
if [ $? -eq 0 ]; then
echo "ok: log ${identify} uploaded to oss!"
return 0
else
echo "error: upload log ${identify} to oss failed!"
return 1
fi
}
function compare(){
cd $workDirectory
cd $workPath
echo "current path: $(pwd)"
if [ ! -f "$fileName" ];then
echo "文件 $fileName 不存在1!"
@ -43,7 +49,7 @@ function compare(){
cd $projectPath
desSum=""
if [ ! -f "$fileName" ];then
cp $workDirectory$fileName .
cp $workPath/$fileName .
return 0
else
desSum=$(md5sum $fileName)
@ -53,7 +59,7 @@ function compare(){
fi
if [ ${oriSum} = ${desSum} ];then
#journalctl -n 1000 -xe -t autoDeploy > ${workDirectory}autoDeploy.log
#journalctl -n 1000 -xe -t autoDeploy > ${workPath}/autoDeploy.log
return 0
else
return 1
@ -87,8 +93,8 @@ function main(){
exit 0
fi
restart
sleep 10
uploadLog
sleep 15
uploadLog u $serviceName 500
echo "ok: checkService done"
echo " "
exit 0

@ -1,82 +1,130 @@
#!/bin/bash
# Usage:
# ./frontEndUpgrade.sh html.zip "/etc/nginx"
fileName=$1
projectPath=$2
# ./frontEndUpgrade.sh html.zip "/etc/nginx" "/home/admin.hq" "production/investigate/frontEnd"
# ./frontEndUpgrade.sh html.zip "/var/www" "/home/ubuntu" "stage/investigate/frontEnd"
fileName=$1 # html.zip zhuize.zip
projectPath=$2 # /etc/nginx /var/www
workPath=$3
ossLogPath=$4
PATH=PATH:/usr/bin:/usr/sbin
echo "1"
projectName="${fileName%.*}"
projectName="${fileName%.*}" # html, zhuize
user="${workPath##*/}"
function uploadLog()
{
ctype=$1
identify=$2
count=$3
echo "current user is ${USER}"
journalctl -n $count -xe -${ctype} $identify > ${workPath}/${identify}.log
${workPath}/ossutil cp -f ${workPath}/${identify}.log oss://ztupload/${ossLogPath}/logs/${identify}.log
if [ $? -eq 0 ]; then
echo "ok: log ${identify} uploaded to oss!"
return 0
else
echo "error: upload log ${identify} to oss failed!"
return 1
fi
}
cd ~
echo "current path: $(pwd)"
if [ ! -f "$fileName" ];then
echo "文件 $fileName 不存在1!"
exit 0
fi
function extractHere() {
cd $projectPath
rm $fileName -f | true
rm $projectName -rf | true
cp $workPath/$fileName .
unzip -q $fileName
mv dist $projectName
echo "user: $user"
chgrp $user $projectName -R
chown $user $projectName -R
}
echo "2"
rm dist -fr
echo "3"
oriSum=$(md5sum $fileName)
oriSum="${oriSum% *}"
echo "origin file $fileName md5sum: $oriSum"
echo "4"
function init(){
cd $workPath
if [ ! -f "$fileName" ];then
echo "file $fileName not exist!"
exit 0
fi
if [ ! -d "$projectPath" ]; then
echo "path $prjectPath exist! "
exit 0
fi
if [ ! -d "$projectPath" ]; then
echo "文件夹 $prjectPath 不存在!"
exit 0
fi
rm dist -fr | true
rm $projectName -fr | true
echo "5"
cd $projectPath
desSum=""
echo "6"
if [ ! -d "$projectName" ];then
echo "6.0"
cp ~/$projectName . -r
exit 0
else
cd $projectPath
if [ ! -d "$projectName" ];then
extractHere
fi
if [ ! -f "$fileName" ];then
extractHere
fi
}
function compareMd5(){
cd $workPath
oriSum=$(md5sum $fileName)
oriSum="${oriSum% *}"
echo "locTemp file ${fileName} md5sum: ${oriSum}"
cd $projectPath
desSum=$(md5sum $fileName)
desSum="${desSum% *}"
echo "6.1"
echo "current path: $(pwd)"
echo "destination file ${fileName} md5sum: ${desSum}"
echo "6.2"
fi
echo "project Path ${fileName} md5sum: ${desSum}"
echo "7"
if [ ${oriSum} = ${desSum} ];then
echo "destination file is same with origin fileno need to replace"
exit 0
fi
if [ ${oriSum} = ${desSum} ];then
return 0
else
return 1
fi
}
cd ~
rm dist -fr
rm $projectName -fr
unzip $fileName -fq
echo "projectName: ${projectName}"
mv dist ~/$projectName
cd $projectPath
function replaceFile(){
cd $projectPath
if [ -f "$fileName"_bak2 ];then
rm "${fileName}"_bak2 -fr
fi
if [ -f "${fileame}"_bak1 ];then
mv ${fileName}_bak1 ${fileName}_bak2
fi
if [ -f "$fileName"_bak ];then
mv ${fileName}_bak ${fileName}_bak1
fi
if [ -f "$fileName" ];then
mv ${fileName} ${fileName}_bak
fi
extractHere
return 0
}
echo "8"
if [ -d "$projectName"_bak2 ];then
rm "${projectName}"_bak2 -fr
fi
echo "9"
if [ -d "${projectName}"_bak1 ];then
mv ${projectName}_bak1 ${projectName}_bak2
fi
echo "10"
if [ -d "$projectName"_bak ];then
mv ${projectName}_bak ${projectName}_bak1
fi
echo "11"
if [ -d "$projectName" ];then
mv ${projectName} ${projectName}_bak
fi
echo "12"
cp ~/"${projectName}" . -r
cp ~/"${fileName}" .
echo "done"
function main() {
echo " "
sleep 5
echo "frontEndUpgrade start"
init
compareMd5
result=$?
if [ ${result} = 0 ];then
echo "local temp file ${fileName} is same with ${projectPath}no need to replace"
echo "ok: frontEndUpgrade done"
echo " "
exit 0
else
echo "local temp file $fileName is different from ${projectPath}, will replace..."
fi
replaceFile
result=$?
if [ $result = 0 ];then
echo "ok: replaced done"
else
echo "error: replace faild"
fi
uploadLog t autoDeploy 100
echo " "
}
main