dashenlin-naning-test_build.sh 5.9 KB

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