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

View File

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

View File

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

View File

@ -1,82 +1,130 @@
#!/bin/bash #!/bin/bash
# Usage: # Usage:
# ./frontEndUpgrade.sh html.zip "/etc/nginx" # ./frontEndUpgrade.sh html.zip "/etc/nginx" "/home/admin.hq" "production/investigate/frontEnd"
fileName=$1 # ./frontEndUpgrade.sh html.zip "/var/www" "/home/ubuntu" "stage/investigate/frontEnd"
projectPath=$2 fileName=$1 # html.zip zhuize.zip
projectPath=$2 # /etc/nginx /var/www
workPath=$3
ossLogPath=$4
PATH=PATH:/usr/bin:/usr/sbin PATH=PATH:/usr/bin:/usr/sbin
echo "1" projectName="${fileName%.*}" # html, zhuize
projectName="${fileName%.*}" 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 ~ function extractHere() {
echo "current path: $(pwd)" cd $projectPath
if [ ! -f "$fileName" ];then rm $fileName -f | true
echo "文件 $fileName 不存在1!" rm $projectName -rf | true
cp $workPath/$fileName .
unzip -q $fileName
mv dist $projectName
echo "user: $user"
chgrp $user $projectName -R
chown $user $projectName -R
}
function init(){
cd $workPath
if [ ! -f "$fileName" ];then
echo "file $fileName not exist!"
exit 0 exit 0
fi fi
if [ ! -d "$projectPath" ]; then
echo "2" echo "path $prjectPath exist! "
rm dist -fr
echo "3"
oriSum=$(md5sum $fileName)
oriSum="${oriSum% *}"
echo "origin file $fileName md5sum: $oriSum"
echo "4"
if [ ! -d "$projectPath" ]; then
echo "文件夹 $prjectPath 不存在!"
exit 0 exit 0
fi fi
echo "5" rm dist -fr | true
cd $projectPath rm $projectName -fr | true
desSum=""
echo "6" cd $projectPath
if [ ! -d "$projectName" ];then if [ ! -d "$projectName" ];then
echo "6.0" extractHere
cp ~/$projectName . -r fi
exit 0 if [ ! -f "$fileName" ];then
else extractHere
fi
}
function compareMd5(){
cd $workPath
oriSum=$(md5sum $fileName)
oriSum="${oriSum% *}"
echo "locTemp file ${fileName} md5sum: ${oriSum}"
cd $projectPath
desSum=$(md5sum $fileName) desSum=$(md5sum $fileName)
desSum="${desSum% *}" desSum="${desSum% *}"
echo "6.1" echo "project Path ${fileName} md5sum: ${desSum}"
echo "current path: $(pwd)"
echo "destination file ${fileName} md5sum: ${desSum}"
echo "6.2"
fi
echo "7" if [ ${oriSum} = ${desSum} ];then
if [ ${oriSum} = ${desSum} ];then return 0
echo "destination file is same with origin fileno need to replace" else
return 1
fi
}
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
}
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 exit 0
fi 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 " "
}
cd ~ main
rm dist -fr
rm $projectName -fr
unzip $fileName -fq
echo "projectName: ${projectName}"
mv dist ~/$projectName
cd $projectPath
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"