build.sh 6.1 KB

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