build.sh 6.0 KB

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