From 96f742d0c3a2e1cfee67d72d5e46e4720c0d75ce Mon Sep 17 00:00:00 2001 From: zhoucg <294039255@qq.com> Date: Wed, 15 Oct 2025 11:41:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BD=97=E8=8E=B1=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 00base/01yvan-ext.sh | 2 +- 00base/02yvan-ext-mobile.sh | 2 +- 00base/03xxljob.sh | 2 +- 08luolai/04xxljob-prod.sh | 2 +- 08luolai/05wms83-prod.sh | 22 ++-- 08luolai/06api-prod.sh | 6 +- 08luolai/07api-gateway-prod.sh | 171 ++++++++++++++++++++++++++++++ 08luolai/08wms83-test.sh | 234 +++++++++++++++++++++++++++++++++++++++++ 08luolai/09api-test.sh | 189 +++++++++++++++++++++++++++++++++ 08luolai/10api-gateway-test.sh | 171 ++++++++++++++++++++++++++++++ 08luolai/11wms83-job-prod.sh | 234 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 1020 insertions(+), 15 deletions(-) create mode 100644 08luolai/07api-gateway-prod.sh create mode 100644 08luolai/08wms83-test.sh create mode 100644 08luolai/09api-test.sh create mode 100644 08luolai/10api-gateway-test.sh create mode 100644 08luolai/11wms83-job-prod.sh diff --git a/00base/01yvan-ext.sh b/00base/01yvan-ext.sh index 87d1f17..984c5e3 100644 --- a/00base/01yvan-ext.sh +++ b/00base/01yvan-ext.sh @@ -4,7 +4,7 @@ set -e codePath=/home/www/deploy/yvan-ext gitUrlArr=( - "http://git.yvanui.com/jztd/yvan-ext.git" + "http://58.209.223.126:9191/r/yvan-ext.git" ) branchArr=( diff --git a/00base/02yvan-ext-mobile.sh b/00base/02yvan-ext-mobile.sh index dff6a9a..f6ab4da 100644 --- a/00base/02yvan-ext-mobile.sh +++ b/00base/02yvan-ext-mobile.sh @@ -4,7 +4,7 @@ set -e codePath=/home/www/deploy/yvan-ext-mobile gitUrlArr=( - "http://git.yvanui.com/jztd/yvan-ext-mobile.git" + "http://58.209.223.126:9191/r/yvan-ext-mobile.git" ) branchArr=( diff --git a/00base/03xxljob.sh b/00base/03xxljob.sh index c503fff..4a9aa8c 100644 --- a/00base/03xxljob.sh +++ b/00base/03xxljob.sh @@ -4,7 +4,7 @@ set -e codePath=/home/www/deploy/xxl-job gitUrlArr=( - "http://git.yvanui.com/lizhiwei/xxl-job.git" + "http://58.209.223.126:9191/r/xxl-job.git" ) branchArr=( diff --git a/08luolai/04xxljob-prod.sh b/08luolai/04xxljob-prod.sh index fc145c0..aab55e7 100644 --- a/08luolai/04xxljob-prod.sh +++ b/08luolai/04xxljob-prod.sh @@ -59,7 +59,7 @@ logs() { pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` # 操作参数: deploy restart start stop kill log logs if [ "$cmd" == "deploy" ];then - bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/03xxljob.sh) pull + bash <(curl -s http://git.galaxis.yvanui.com/lizw/jztd-deploy/src/branch/master/00base/03xxljob.sh) pull restartServer $pid elif [ "$cmd" == "restart" ];then restartServer $pid diff --git a/08luolai/05wms83-prod.sh b/08luolai/05wms83-prod.sh index 91c3624..3a57228 100644 --- a/08luolai/05wms83-prod.sh +++ b/08luolai/05wms83-prod.sh @@ -2,10 +2,10 @@ #set -x set -e -codePath=/home/www/deploy/wms8 +codePath=/home/www/deploy/wms83_servo gitUrlArr=( "http://git.galaxis.yvanui.com/wms8/wms83.git" - "http://git.yvanui.com/lizhiwei/yvan-framework.git" + "http://58.209.223.126:9191/r/yvan-framework.git" ) branchArr=( @@ -105,9 +105,9 @@ buildCode() { echo "" } -logPath=/home/www/data/logs/wms8/wms8.log -dirPath=/home/www/deploy/wms8/wms-biz/servo/build/libs/ -serverName=wms8 +logPath=/home/www/data/logs/wms83_servo/wms83_servo.log +dirPath=/home/www/deploy/wms83_servo/wms-biz/servo/build/libs/ +serverName=wms83_servo cmd=$1 profiles=${2:-"prod"} @@ -193,8 +193,8 @@ logs() { } deployYvanUI() { - bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull - bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull } pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` @@ -202,6 +202,7 @@ pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` if [ "$cmd" == "pull" ];then deployYvanUI deployPull + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/11wms83-job-prod.sh) pull if [ -z $pid ];then echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs" fi @@ -209,16 +210,21 @@ elif [ "$cmd" == "build" ];then deployYvanUI deployPull buildCode + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/11wms83-job-prod.sh) build echo "###--代码构建完成--------------------------------------------------------------------------###" elif [ "$cmd" == "deploy" ];then deployYvanUI deployServer $pid + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/11wms83-job-prod.sh) deploy elif [ "$cmd" == "restart" ];then restartServer $pid + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/11wms83-job-prod.sh) restart elif [ "$cmd" == "start" ];then startServer $pid + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/11wms83-job-prod.sh) start elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then stopServer $pid + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/11wms83-job-prod.sh) stop elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then logs else @@ -231,4 +237,4 @@ else fi fi -# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/08luolai/05wms83-prod.sh) [cmd profiles] +# bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/05wms83-prod.sh) [cmd profiles] diff --git a/08luolai/06api-prod.sh b/08luolai/06api-prod.sh index f305019..786f317 100644 --- a/08luolai/06api-prod.sh +++ b/08luolai/06api-prod.sh @@ -5,7 +5,7 @@ set -e codePath=/home/www/deploy/wms8_api gitUrlArr=( "http://git.galaxis.yvanui.com/wms8/wms83.git" - "http://git.yvanui.com/lizhiwei/yvan-framework.git" + "http://58.209.223.126:9191/r/yvan-framework.git" ) branchArr=( @@ -82,7 +82,7 @@ cmd=$1 profiles=${2:-"prod"} #------------------------------------------------------------------- -JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g" +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx4g -Xms4g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m" DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false" JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai -Duser.name=user" #------------------------------------------------------------------- @@ -186,4 +186,4 @@ else fi fi -# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/08luolai/06api-prod.sh) [cmd profiles] +# bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/06api-prod.sh) [cmd profiles] diff --git a/08luolai/07api-gateway-prod.sh b/08luolai/07api-gateway-prod.sh new file mode 100644 index 0000000..a8fc1c1 --- /dev/null +++ b/08luolai/07api-gateway-prod.sh @@ -0,0 +1,171 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/api_gateway +gitUrlArr=( + "http://58.209.223.126:9191/r/api-gateway.git" +) + +branchArr=( + "master" +) +positionArr=( + "." +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +isChange="1" # 仓库是否发生变化,0:未变化;非0:变化 +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 java + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd $codePath + echo -e "$echoPrefix chmod +x gradlew $echoSuffix" + chmod +x gradlew + echo -e "$echoPrefix ./gradlew build -x test $echoSuffix" + ./gradlew build -x test + echo "" +} + +logPath=/home/www/data/logs/api_gateway/api_gateway.log +dirPath=/home/www/deploy/api_gateway/api-gateway-server/build/libs/ +serverName=api_gateway + +cmd=$1 +profiles=${2:-"luolai-prod"} + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx1g -Xms1g" +DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false" +JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai" +#------------------------------------------------------------------- + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix cd $dirPath $echoSuffix" + cd $dirPath + echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./api-gateway-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=9010 >>/dev/null 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./api-gateway-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=9010 >>/dev/null 2>&1 & + echo "$serverName 启动成功!" + else + echo "$serverName 正在运行..." + fi + echo "查看日志: tail -F $logPath -n 100" +} + +stopServer() { + pid=$1 + if [ -z $pid ];then + echo "$serverName 未运行" + else + echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix" + ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill + echo "$serverName 已停止!" + fi +} + +deployPull() { + for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do + pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]} + if [ "${needBuild[idx]}" == "-1" ]; then + needBuild[idx]=$isChange + fi + done + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +deployServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 8s + fi + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" + echo "" + startServer +} + +restartServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + startServer +} + +logs() { + tail -F $logPath -n 100 +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: deploy restart start stop kill log logs +if [ "$cmd" == "deploy" ];then + deployServer $pid +elif [ "$cmd" == "restart" ];then + restartServer $pid +elif [ "$cmd" == "start" ];then + startServer $pid +elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then + stopServer $pid +elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then + logs +else + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: deploy restart start stop kill log logs" + else + echo "输入操作参数: deploy restart start stop kill log logs" + echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100" + fi +fi + +# bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/07api-gateway-prod.sh) [cmd profiles] diff --git a/08luolai/08wms83-test.sh b/08luolai/08wms83-test.sh new file mode 100644 index 0000000..3cd16f9 --- /dev/null +++ b/08luolai/08wms83-test.sh @@ -0,0 +1,234 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/wms8_test +gitUrlArr=( + "http://git.galaxis.yvanui.com/wms8/wms83.git" + "http://58.209.223.126:9191/r/yvan-framework.git" +) + +branchArr=( + "luolai" + "8.3" +) +positionArr=( + "." + "yvan-framework" +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +isChange="1" # 仓库是否发生变化,0:未变化;非0:变化 +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"luolai"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 wms-biz/bundle + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/wms-biz/bundle $echoSuffix" + cd "$codePath/wms-biz/bundle" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link yvan-ext $echoSuffix" + yarn link yvan-ext + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "wms-biz/bundle 文件未变化" + fi + + # 构建 wms-biz/pda-client + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/wms-biz/pda-client $echoSuffix" + cd "$codePath/wms-biz/pda-client" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix" + yarn link yvan-ext-mobile + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "wms-biz/pda-client 文件未变化" + fi + + # 构建 java + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd $codePath + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" +} + +logPath=/home/www/data/logs/wms8_test/wms8_test.log +dirPath=/home/www/deploy/wms8_test/wms-biz/servo/build/libs/ +serverName=wms8_test + +cmd=$1 +profiles=${2:-"luolai-test"} + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g" +DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false" +JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai" +#------------------------------------------------------------------- + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix" + cd $dirPath../runtime/ + echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8102 >>/dev/null 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8102 >>/dev/null 2>&1 & + echo "$serverName 启动成功!" + else + echo "$serverName 正在运行..." + fi + echo "查看日志: tail -F $logPath -n 100" +} + +stopServer() { + pid=$1 + if [ -z $pid ];then + echo "$serverName 未运行" + else + echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix" + ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill + echo "$serverName 已停止!" + fi +} + +deployPull() { + for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do + pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]} + if [ "${needBuild[idx]}" == "-1" ]; then + needBuild[idx]=$isChange + fi + done + # 设置 require_config.js 前端版本 + version=$(date +_%Y_%m_%d_%H_%M_%S) + echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $codePath/public/require_config.js $echoSuffix" + sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $codePath/public/require_config.js + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +deployServer() { + pid=$1 + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" + # 重启服务 + if [ ! -z $pid ];then + stopServer $pid + sleep 8s + fi + # 移动编译后的文件 + echo -e "$echoPrefix cd $dirPath $echoSuffix" + cd $dirPath + echo -e "$echoPrefix rm -rf ../runtime $echoSuffix" + rm -rf ../runtime + echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix" + cp -r ./ ../runtime + echo "" + startServer +} + +restartServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + startServer +} + +logs() { + tail -F $logPath -n 100 +} + +deployYvanUI() { + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: pull build deploy restart start stop kill log logs +if [ "$cmd" == "pull" ];then + deployYvanUI + deployPull + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs" + fi +elif [ "$cmd" == "build" ];then + deployYvanUI + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" +elif [ "$cmd" == "deploy" ];then + deployYvanUI + deployServer $pid +elif [ "$cmd" == "restart" ];then + restartServer $pid +elif [ "$cmd" == "start" ];then + startServer $pid +elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then + stopServer $pid +elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then + logs +else + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs" + echo "查看日志: tail -F $logPath -n 100" + else + echo "输入操作参数: pull build deploy restart start stop kill log logs" + echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100" + fi +fi + +# bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/08wms83-test.sh) [cmd profiles] diff --git a/08luolai/09api-test.sh b/08luolai/09api-test.sh new file mode 100644 index 0000000..3b70baa --- /dev/null +++ b/08luolai/09api-test.sh @@ -0,0 +1,189 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/wms8_api_test +gitUrlArr=( + "http://git.galaxis.yvanui.com/wms8/wms83.git" + "http://58.209.223.126:9191/r/yvan-framework.git" +) + +branchArr=( + "luolai" + "8.3" +) +positionArr=( + "." + "yvan-framework" +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +isChange="1" # 仓库是否发生变化,0:未变化;非0:变化 +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"luolai"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 java + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd $codePath + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" +} + +logPath=/home/www/data/logs/wms8_api_test/wms8_api_test.log +dirPath=/home/www/deploy/wms8_api_test/wms-biz/wms8-api/build/libs/ +serverName=wms8_api_test + +cmd=$1 +profiles=${2:-"luolai-test"} + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g" +DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false" +JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai -Duser.name=user" +#------------------------------------------------------------------- + +moveBuildFile() { + # 移动编译后的文件 + echo -e "$echoPrefix cd $dirPath $echoSuffix" + cd $dirPath + echo -e "$echoPrefix rm -rf ../runtime $echoSuffix" + rm -rf ../runtime + echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix" + cp -r ./ ../runtime + echo "" +} + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix" + cd $dirPath../runtime/ + echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./wms8-api-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8095 >>/dev/null 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./wms8-api-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8095 >>/dev/null 2>&1 & + echo "$serverName 启动成功!" + else + echo "$serverName 正在运行..." + fi + echo "查看日志: tail -F $logPath -n 100" +} + +stopServer() { + pid=$1 + if [ -z $pid ];then + echo "$serverName 未运行" + else + echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix" + ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill + echo "$serverName 已停止!" + fi +} + +deployPull() { + for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do + pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]} + if [ "${needBuild[idx]}" == "-1" ]; then + needBuild[idx]=$isChange + fi + done + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +deployServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 8s + fi + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" + moveBuildFile + startServer +} + +restartServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + moveBuildFile + startServer +} + +logs() { + tail -F $logPath -n 100 +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: build deploy restart start stop kill log logs +if [ "$cmd" == "build" ];then + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" +elif [ "$cmd" == "deploy" ];then + deployServer $pid +elif [ "$cmd" == "restart" ];then + restartServer $pid +elif [ "$cmd" == "start" ];then + startServer $pid +elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then + stopServer $pid +elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then + logs +else + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: build deploy restart start stop kill log logs" + else + echo "输入操作参数: build deploy restart start stop kill log logs" + echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100" + fi +fi + +# bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/09api-test.sh) [cmd profiles] diff --git a/08luolai/10api-gateway-test.sh b/08luolai/10api-gateway-test.sh new file mode 100644 index 0000000..2fe4a40 --- /dev/null +++ b/08luolai/10api-gateway-test.sh @@ -0,0 +1,171 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/api_gateway_test +gitUrlArr=( + "http://58.209.223.126:9191/r/api-gateway.git" +) + +branchArr=( + "master" +) +positionArr=( + "." +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +isChange="1" # 仓库是否发生变化,0:未变化;非0:变化 +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 java + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd $codePath + echo -e "$echoPrefix chmod +x gradlew $echoSuffix" + chmod +x gradlew + echo -e "$echoPrefix ./gradlew build -x test $echoSuffix" + ./gradlew build -x test + echo "" +} + +logPath=/home/www/data/logs/api_gateway_test/api_gateway_test.log +dirPath=/home/www/deploy/api_gateway_test/api-gateway-server/build/libs/ +serverName=api_gateway_test + +cmd=$1 +profiles=${2:-"luolai-test"} + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx1g -Xms1g" +DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false" +JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai" +#------------------------------------------------------------------- + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix cd $dirPath $echoSuffix" + cd $dirPath + echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./api-gateway-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=9011 >>/dev/null 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./api-gateway-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=9011 >>/dev/null 2>&1 & + echo "$serverName 启动成功!" + else + echo "$serverName 正在运行..." + fi + echo "查看日志: tail -F $logPath -n 100" +} + +stopServer() { + pid=$1 + if [ -z $pid ];then + echo "$serverName 未运行" + else + echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix" + ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill + echo "$serverName 已停止!" + fi +} + +deployPull() { + for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do + pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]} + if [ "${needBuild[idx]}" == "-1" ]; then + needBuild[idx]=$isChange + fi + done + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +deployServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 8s + fi + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" + echo "" + startServer +} + +restartServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + startServer +} + +logs() { + tail -F $logPath -n 100 +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: deploy restart start stop kill log logs +if [ "$cmd" == "deploy" ];then + deployServer $pid +elif [ "$cmd" == "restart" ];then + restartServer $pid +elif [ "$cmd" == "start" ];then + startServer $pid +elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then + stopServer $pid +elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then + logs +else + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: deploy restart start stop kill log logs" + else + echo "输入操作参数: deploy restart start stop kill log logs" + echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100" + fi +fi + +# bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/10api-gateway-test.sh) [cmd profiles] diff --git a/08luolai/11wms83-job-prod.sh b/08luolai/11wms83-job-prod.sh new file mode 100644 index 0000000..694351a --- /dev/null +++ b/08luolai/11wms83-job-prod.sh @@ -0,0 +1,234 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/wms8_job +gitUrlArr=( + "http://git.galaxis.yvanui.com/wms8/wms83.git" + "http://58.209.223.126:9191/r/yvan-framework.git" +) + +branchArr=( + "luolai" + "8.3" +) +positionArr=( + "." + "yvan-framework" +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + + +# 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master +isChange="1" # 仓库是否发生变化,0:未变化;非0:变化 +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"luolai"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 wms-biz/bundle + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/wms-biz/bundle $echoSuffix" + cd "$codePath/wms-biz/bundle" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link yvan-ext $echoSuffix" + yarn link yvan-ext + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "wms-biz/bundle 文件未变化" + fi + + # 构建 wms-biz/pda-client + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/wms-biz/pda-client $echoSuffix" + cd "$codePath/wms-biz/pda-client" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix" + yarn link yvan-ext-mobile + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "wms-biz/pda-client 文件未变化" + fi + + # 构建 java + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd $codePath + echo -e "$echoPrefix gradle build -x test $echoSuffix" + gradle build -x test + echo "" +} + +logPath=/home/www/data/logs/wms8_job/wms8_job.log +dirPath=/home/www/deploy/wms8_job/wms-biz/servo/build/libs/ +serverName=wms8_job + +cmd=$1 +profiles=${2:-"job-prod"} + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g" +DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false" +JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai" +#------------------------------------------------------------------- + +startServer() { + pid=$1 + if [ -z $pid ];then + echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix" + cd $dirPath../runtime/ + echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8201 >>/dev/null 2>&1 & $echoSuffix" + java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8201 >>/dev/null 2>&1 & + echo "$serverName 启动成功!" + else + echo "$serverName 正在运行..." + fi + echo "查看日志: tail -F $logPath -n 100" +} + +stopServer() { + pid=$1 + if [ -z $pid ];then + echo "$serverName 未运行" + else + echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix" + ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill + echo "$serverName 已停止!" + fi +} + +deployPull() { + for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do + pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]} + if [ "${needBuild[idx]}" == "-1" ]; then + needBuild[idx]=$isChange + fi + done + # 设置 require_config.js 前端版本 + version=$(date +_%Y_%m_%d_%H_%M_%S) + echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $codePath/public/require_config.js $echoSuffix" + sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $codePath/public/require_config.js + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +deployServer() { + pid=$1 + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" + # 重启服务 + if [ ! -z $pid ];then + stopServer $pid + sleep 8s + fi + # 移动编译后的文件 + echo -e "$echoPrefix cd $dirPath $echoSuffix" + cd $dirPath + echo -e "$echoPrefix rm -rf ../runtime $echoSuffix" + rm -rf ../runtime + echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix" + cp -r ./ ../runtime + echo "" + startServer +} + +restartServer() { + pid=$1 + if [ ! -z $pid ];then + stopServer $pid + sleep 3s + fi + startServer +} + +logs() { + tail -F $logPath -n 100 +} + +deployYvanUI() { + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull + bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull +} + +pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'` +# 操作参数: pull build deploy restart start stop kill log logs +if [ "$cmd" == "pull" ];then + deployYvanUI + deployPull + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs" + fi +elif [ "$cmd" == "build" ];then + deployYvanUI + deployPull + buildCode + echo "###--代码构建完成--------------------------------------------------------------------------###" +elif [ "$cmd" == "deploy" ];then + deployYvanUI + deployServer $pid +elif [ "$cmd" == "restart" ];then + restartServer $pid +elif [ "$cmd" == "start" ];then + startServer $pid +elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then + stopServer $pid +elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then + logs +else + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs" + echo "查看日志: tail -F $logPath -n 100" + else + echo "输入操作参数: pull build deploy restart start stop kill log logs" + echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100" + fi +fi + +# bash <(curl -s http://git.yvanui.com/projects/jztd-deploy/raw/master/08luolai/11wms83-job-prod.sh) [cmd profiles]