123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #!/bin/bash
- #set -x
- set -e
- codePath=/data3/thinkingwms-ui2
- gitUrlArr=(
- "http://git.yvanui.com/jztd/thinkingwms-ui.git"
- "http://git.yvanui.com/jztd/yvan-ext.git"
- "http://git.yvanui.com/jztd/yvan-ext-mobile.git"
- )
- branchArr=(
- "mega"
- "master"
- "master"
- )
- positionArr=(
- "."
- "yvan-ext"
- "yvan-ext-mobile"
- )
- # 是否需要构建,-1:自动;0:不需要;1:需要
- needBuild=(
- "1"
- "1"
- "1"
- )
- echoPrefix="\033[36m+"
- echoSuffix="\033[0m"
- 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 ""
- }
- 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 -e "$echoPrefix sed -i 's/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g' $codePath/client/public/login.html $echoSuffix"
- sed -i "s/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g" $codePath/client/public/login.html
- echo -e "$echoPrefix sed -i 's/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g' $codePath/client/src/ApiConvert.js $echoSuffix"
- sed -i "s/10\.100\.166\.15:8770/139\.9\.249\.180:8770/g" $codePath/client/src/ApiConvert.js
- echo "###--代码更新完成--------------------------------------------------------------------------###"
- echo ""
- buildCode() {
- # 构建 yvan-ext
- if [ "${needBuild[1]}" != "0" ]; then
- echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
- cd "$codePath/yvan-ext"
- # echo -e "$echoPrefix git reset --hard 22f18ac82221b4c6889696d500bfeb2981a2f3e1 $echoSuffix"
- # git reset --hard 22f18ac82221b4c6889696d500bfeb2981a2f3e1
- 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[1]}" != "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
- # 构建 thinkingwms-ui/client
- if [ "${needBuild[2]}" != "0" ]; then
- echo -e "$echoPrefix cd $codePath/client $echoSuffix"
- cd "$codePath/client"
- 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 "thinkingwms-ui/client 文件未变化"
- fi
- # 构建 thinkingwms-ui/pda-client
- if [ "${needBuild[2]}" != "0" ]; then
- echo -e "$echoPrefix cd $codePath/pda-client $echoSuffix"
- cd "$codePath/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 "thinkingwms-ui/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 ""
- }
- buildCode
- echo "###--代码构建完成--------------------------------------------------------------------------###"
- echo ""
- logPath=/data3/thinkingwms_nohup2.log
- dirPath=/data3/thinkingwms-ui2/thinkingwms-backend/build/libs/
- serverName=2dsl_thinkingwms_ui
- cmd=$1
- profiles=${2:-"test_hwy"}
- #-------------------------------------------------------------------
- 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 $echoSuffix"
- cd $dirPath
- echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./thinkingwms-backend-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=3300 >$logPath 2>&1 & $echoSuffix"
- java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./thinkingwms-backend-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=3300 >$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
- }
- pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
- if [ ! -z $pid ];then
- stopServer $pid
- sleep 3s
- fi
- startServer
- # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/build-mega.sh)
|