From 3115655d03d700508898c4106528a1f187149997 Mon Sep 17 00:00:00 2001 From: lizw Date: Fri, 1 Apr 2022 13:07:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=8D=97=E4=B8=80=E5=BF=83=E5=A0=82?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=20pre-deploy-wms8.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yxt-yn/deploy-wms8.sh | 250 ---------------------------------------------- yxt-yn/pre-deploy-wms8.sh | 250 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+), 250 deletions(-) delete mode 100644 yxt-yn/deploy-wms8.sh create mode 100644 yxt-yn/pre-deploy-wms8.sh diff --git a/yxt-yn/deploy-wms8.sh b/yxt-yn/deploy-wms8.sh deleted file mode 100644 index d425a80..0000000 --- a/yxt-yn/deploy-wms8.sh +++ /dev/null @@ -1,250 +0,0 @@ -#!/bin/bash -#set -x -set -e - -codePath=/home/www/deploy/wms8_pre -gitUrlArr=( - "http://git.galaxis.yvanui.com/wms8/wms8-bench.git" - "http://git.yvanui.com/jztd/yvan-ext.git" - "http://git.yvanui.com/lizhiwei/yvan-framework.git" - "http://git.galaxis.yvanui.com/wms8/wms-core.git" - "http://git.yvanui.com/jztd/yvan-ext-mobile.git" -) - -branchArr=( - "master" - "master" - "master" - "master" - "master" -) -positionArr=( - "." - "yvan-ext" - "yvan-framework" - "wms-core" - "yvan-ext-mobile" -) -# 是否需要构建,-1:自动;0:不需要;1:需要 -needBuild=( -"1" -"1" -"1" -"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:-"master"} # git分支 - position=${4:-""} # 使用“.”clone到当前文件夹 - isChange="1" - # 创建文件夹 - if [ ! -d "$path" ]; then - echo -e "$echoPrefix mkdir -p $path $echoSuffix" - mkdir -p $path - 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() { - # 构建 yvan-ext - if [ "${needBuild[1]}" != "0" ]; then - echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix" - cd "$codePath/yvan-ext" - echo -e "$echoPrefix yarn $echoSuffix" - yarn - echo -e "$echoPrefix yarn link $echoSuffix" - yarn link - echo -e "$echoPrefix yarn build $echoSuffix" - yarn build - echo "" - else - echo "yvan-ext 文件未变化" - fi - - # 构建 yvan-ext-mobile - if [ "${needBuild[4]}" != "0" ]; then - echo -e "$echoPrefix cd $codePath/yvan-ext-mobile $echoSuffix" - cd "$codePath/yvan-ext-mobile" - echo -e "$echoPrefix yarn $echoSuffix" - yarn - echo -e "$echoPrefix yarn link $echoSuffix" - yarn link - echo -e "$echoPrefix yarn build $echoSuffix" - yarn build - echo "" - else - echo "yvan-ext-mobile 文件未变化" - fi - - # 构建 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/output/wms8_pre_nohup.log -dirPath=/home/www/deploy/wms8_pre/wms-biz/servo/build/libs/ -serverName=wms8_pre - -cmd=$1 -profiles=${2:-"pre-yn"} - -#------------------------------------------------------------------- -JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx16g -Xms16g" -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 ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8095 >$logPath 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=8095 >$logPath 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 3s - 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}'` -# 操作参数: pull deploy restart start stop kill log logs -if [ "$cmd" == "pull" ];then - deployPull - if [ -z $pid ];then - echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs" - fi -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 未运行 | 输入操作参数: pull deploy restart start stop kill log logs" - else - echo "输入操作参数: pull 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/lizhiwei/jztd-deploy/raw/master/yxt-yn/deploy-wms8.sh) [cmd profiles] diff --git a/yxt-yn/pre-deploy-wms8.sh b/yxt-yn/pre-deploy-wms8.sh new file mode 100644 index 0000000..d425a80 --- /dev/null +++ b/yxt-yn/pre-deploy-wms8.sh @@ -0,0 +1,250 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/www/deploy/wms8_pre +gitUrlArr=( + "http://git.galaxis.yvanui.com/wms8/wms8-bench.git" + "http://git.yvanui.com/jztd/yvan-ext.git" + "http://git.yvanui.com/lizhiwei/yvan-framework.git" + "http://git.galaxis.yvanui.com/wms8/wms-core.git" + "http://git.yvanui.com/jztd/yvan-ext-mobile.git" +) + +branchArr=( + "master" + "master" + "master" + "master" + "master" +) +positionArr=( + "." + "yvan-ext" + "yvan-framework" + "wms-core" + "yvan-ext-mobile" +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +"1" +"1" +"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:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix mkdir -p $path $echoSuffix" + mkdir -p $path + 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() { + # 构建 yvan-ext + if [ "${needBuild[1]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix" + cd "$codePath/yvan-ext" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link $echoSuffix" + yarn link + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "yvan-ext 文件未变化" + fi + + # 构建 yvan-ext-mobile + if [ "${needBuild[4]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath/yvan-ext-mobile $echoSuffix" + cd "$codePath/yvan-ext-mobile" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link $echoSuffix" + yarn link + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "yvan-ext-mobile 文件未变化" + fi + + # 构建 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/output/wms8_pre_nohup.log +dirPath=/home/www/deploy/wms8_pre/wms-biz/servo/build/libs/ +serverName=wms8_pre + +cmd=$1 +profiles=${2:-"pre-yn"} + +#------------------------------------------------------------------- +JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx16g -Xms16g" +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 ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8095 >$logPath 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=8095 >$logPath 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 3s + 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}'` +# 操作参数: pull deploy restart start stop kill log logs +if [ "$cmd" == "pull" ];then + deployPull + if [ -z $pid ];then + echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs" + fi +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 未运行 | 输入操作参数: pull deploy restart start stop kill log logs" + else + echo "输入操作参数: pull 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/lizhiwei/jztd-deploy/raw/master/yxt-yn/deploy-wms8.sh) [cmd profiles]