13haerbing-test_build.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=/home/www/deploy/thinkingwms-ui_haerbing-test
  5. gitUrlArr=(
  6. #"http://git.yvanui.com/jztd/thinkingwms-ui.git"
  7. #"http://dsl-third-gitlab.dslyy.com/kls/wms/thinkingwms-ui.git"
  8. "www@git.yvanui.com:jztd/thinkingwms-ui.git"
  9. "http://git.yvanui.com/jztd/yvan-ext.git"
  10. "http://git.yvanui.com/jztd/yvan-ext-mobile.git"
  11. )
  12. branchArr=(
  13. "harb-bck"
  14. "master"
  15. "master"
  16. )
  17. positionArr=(
  18. "."
  19. "yvan-ext"
  20. "yvan-ext-mobile"
  21. )
  22. # 是否需要构建,-1:自动;0:不需要;1:需要
  23. needBuild=(
  24. "1"
  25. "1"
  26. "1"
  27. )
  28. echoPrefix="\033[36m+"
  29. echoSuffix="\033[0m"
  30. isChange="1" # 仓库是否发生变化,0:未变化;非0:变化
  31. pullCode() {
  32. # Usage: pullCode "codePath" "gitUrl" "branch" "position"
  33. path=$1 # 代码保存路径
  34. gitUrl=$2 # git仓库地址
  35. branch=${3:-"master"} # git分支
  36. position=${4:-""} # 使用“.”clone到当前文件夹
  37. isChange="1"
  38. # 创建文件夹
  39. if [ ! -d "$path" ]; then
  40. echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix"
  41. exit
  42. fi
  43. # git clone
  44. echo -e "$echoPrefix cd $path $echoSuffix"
  45. cd $path
  46. if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
  47. echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
  48. git clone $gitUrl $position
  49. isChange="2"
  50. fi
  51. # 进入文件夹,切换分支,git pull
  52. if [ "$position" != "" ]; then
  53. echo -e "$echoPrefix cd $position $echoSuffix"
  54. cd $position
  55. fi
  56. echo -e "$echoPrefix git checkout $branch $echoSuffix"
  57. git checkout $branch
  58. echo -e "$echoPrefix git checkout . $echoSuffix"
  59. git checkout .
  60. echo -e "$echoPrefix git pull $echoSuffix"
  61. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
  62. isChange="0"
  63. fi
  64. echo ""
  65. }
  66. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  67. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  68. if [ "${needBuild[idx]}" == "-1" ]; then
  69. needBuild[idx]=$isChange
  70. fi
  71. done
  72. echo "###--代码更新完成--------------------------------------------------------------------------###"
  73. echo ""
  74. echo -e "$echoPrefix sed -i 's/10\.100\.166\.15:8770/10\.100\.186\.50:8770/g' $codePath/client/public/login.html $echoSuffix"
  75. sed -i "s/10\.100\.166\.15:8770/10\.100\.186\.50:8770/g" $codePath/client/public/login.html
  76. echo -e "$echoPrefix sed -i 's/10\.100\.166\.15:8770/10\.100\.186\.50:8770/g' $codePath/client/src/ApiConvert.js $echoSuffix"
  77. sed -i "s/10\.100\.166\.15:8770/10\.100\.186\.50:8770/g" $codePath/client/src/ApiConvert.js
  78. echo "###--代码更新完成--------------------------------------------------------------------------###"
  79. echo ""
  80. buildCode() {
  81. # 构建 yvan-ext
  82. if [ "${needBuild[1]}" != "0" ]; then
  83. echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
  84. cd "$codePath/yvan-ext"
  85. echo -e "$echoPrefix yarn --network-timeout 1000 $echoSuffix"
  86. yarn --network-timeout 1000
  87. echo -e "$echoPrefix yarn link $echoSuffix"
  88. yarn link
  89. echo -e "$echoPrefix yarn build $echoSuffix"
  90. yarn build
  91. echo ""
  92. else
  93. echo "yvan-ext 文件未变化"
  94. fi
  95. # 构建 yvan-ext-mobile
  96. if [ "${needBuild[1]}" != "0" ]; then
  97. echo -e "$echoPrefix cd $codePath/yvan-ext-mobile $echoSuffix"
  98. cd "$codePath/yvan-ext-mobile"
  99. echo -e "$echoPrefix yarn --network-timeout 1000 $echoSuffix"
  100. yarn --network-timeout 1000
  101. echo -e "$echoPrefix yarn link $echoSuffix"
  102. yarn link
  103. echo -e "$echoPrefix yarn build $echoSuffix"
  104. yarn build
  105. echo ""
  106. else
  107. echo "yvan-ext-mobile 文件未变化"
  108. fi
  109. # 构建 thinkingwms-ui/client
  110. if [ "${needBuild[2]}" != "0" ]; then
  111. echo -e "$echoPrefix cd $codePath/client $echoSuffix"
  112. cd "$codePath/client"
  113. echo -e "$echoPrefix yarn --network-timeout 1000 $echoSuffix"
  114. yarn --network-timeout 1000
  115. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  116. yarn link yvan-ext
  117. echo -e "$echoPrefix yarn build $echoSuffix"
  118. yarn build
  119. echo ""
  120. else
  121. echo "thinkingwms-ui/client 文件未变化"
  122. fi
  123. # 构建 thinkingwms-ui/pda-client
  124. if [ "${needBuild[2]}" != "0" ]; then
  125. echo -e "$echoPrefix cd $codePath/pda-client $echoSuffix"
  126. cd "$codePath/pda-client"
  127. echo -e "$echoPrefix yarn --network-timeout 1000 $echoSuffix"
  128. yarn --network-timeout 1000
  129. echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix"
  130. yarn link yvan-ext-mobile
  131. echo -e "$echoPrefix yarn build $echoSuffix"
  132. yarn build
  133. echo ""
  134. else
  135. echo "thinkingwms-ui/pda-client 文件未变化"
  136. fi
  137. # 构建 java
  138. echo -e "$echoPrefix cd $codePath $echoSuffix"
  139. cd $codePath
  140. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  141. gradle build -x test
  142. echo ""
  143. }
  144. buildCode
  145. echo "###--代码构建完成--------------------------------------------------------------------------###"
  146. echo ""
  147. logPath=/data/logs/dsl_dashenlin_haerbing_test_thinkingwms_ui.log
  148. dirPath=/home/www/deploy/thinkingwms-ui_haerbing-test/thinkingwms-backend/build/libs/
  149. serverName=dsl_dashenlin_haerbing_test_thinkingwms_ui
  150. cmd=$1
  151. profiles=${2:-"test_haerbing3"}
  152. #-------------------------------------------------------------------
  153. JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g"
  154. DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
  155. JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
  156. #-------------------------------------------------------------------
  157. startServer() {
  158. pid=$1
  159. if [ -z $pid ];then
  160. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  161. cd $dirPath
  162. 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=8007 >$logPath 2>&1 & $echoSuffix"
  163. java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./thinkingwms-backend-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8007 >$logPath 2>&1 &
  164. echo "$serverName 启动成功!"
  165. else
  166. echo "$serverName 正在运行..."
  167. fi
  168. echo "查看日志: tail -F $logPath -n 100"
  169. }
  170. stopServer() {
  171. pid=$1
  172. if [ -z $pid ];then
  173. echo "$serverName 未运行"
  174. else
  175. echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill -9 $echoSuffix"
  176. ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill -9
  177. echo "$serverName 已停止!"
  178. fi
  179. }
  180. pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
  181. if [ ! -z $pid ];then
  182. stopServer $pid
  183. sleep 3s
  184. fi
  185. startServer
  186. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/hua_wei_yun/13haerbing-test_build.sh)