build.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. "master"
  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 pull $echoSuffix"
  57. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
  58. isChange="0"
  59. fi
  60. echo ""
  61. }
  62. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  63. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  64. if [ "${needBuild[idx]}" == "-1" ]; then
  65. needBuild[idx]=$isChange
  66. fi
  67. done
  68. echo "###--代码更新完成--------------------------------------------------------------------------###"
  69. echo ""
  70. buildCode() {
  71. # 构建 yvan-ext
  72. if [ "${needBuild[1]}" != "0" ]; then
  73. echo -e "$echoPrefix cd $codePath/yvan-ext $echoSuffix"
  74. cd "$codePath/yvan-ext"
  75. echo -e "$echoPrefix yarn $echoSuffix"
  76. yarn
  77. echo -e "$echoPrefix yarn link $echoSuffix"
  78. yarn link
  79. echo -e "$echoPrefix yarn build $echoSuffix"
  80. yarn build
  81. echo ""
  82. else
  83. echo "yvan-ext 文件未变化"
  84. fi
  85. # 构建 yvan-ext-mobile
  86. if [ "${needBuild[1]}" != "0" ]; then
  87. echo -e "$echoPrefix cd $codePath/yvan-ext-mobile $echoSuffix"
  88. cd "$codePath/yvan-ext-mobile"
  89. echo -e "$echoPrefix yarn $echoSuffix"
  90. yarn
  91. echo -e "$echoPrefix yarn link $echoSuffix"
  92. yarn link
  93. echo -e "$echoPrefix yarn build $echoSuffix"
  94. yarn build
  95. echo ""
  96. else
  97. echo "yvan-ext-mobile 文件未变化"
  98. fi
  99. # 构建 thinkingwms-ui/client
  100. if [ "${needBuild[2]}" != "0" ]; then
  101. echo -e "$echoPrefix cd $codePath/client $echoSuffix"
  102. cd "$codePath/client"
  103. echo -e "$echoPrefix yarn $echoSuffix"
  104. yarn
  105. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  106. yarn link yvan-ext
  107. echo -e "$echoPrefix yarn build $echoSuffix"
  108. yarn build
  109. echo ""
  110. else
  111. echo "thinkingwms-ui/client 文件未变化"
  112. fi
  113. # 构建 thinkingwms-ui/pda-client
  114. if [ "${needBuild[2]}" != "0" ]; then
  115. echo -e "$echoPrefix cd $codePath/pda-client $echoSuffix"
  116. cd "$codePath/pda-client"
  117. echo -e "$echoPrefix yarn $echoSuffix"
  118. yarn
  119. echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix"
  120. yarn link yvan-ext-mobile
  121. echo -e "$echoPrefix yarn build $echoSuffix"
  122. yarn build
  123. echo ""
  124. else
  125. echo "thinkingwms-ui/pda-client 文件未变化"
  126. fi
  127. # 构建 java
  128. echo -e "$echoPrefix cd $codePath $echoSuffix"
  129. cd $codePath
  130. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  131. gradle build -x test
  132. echo ""
  133. }
  134. buildCode
  135. echo "###--代码构建完成--------------------------------------------------------------------------###"
  136. echo ""
  137. logPath=/data3/thinkingwms_nohup.log
  138. dirPath=/data3/thinkingwms-ui/thinkingwms-backend/build/libs/
  139. serverName=dsl_thinkingwms_ui
  140. cmd=$1
  141. profiles=${2:-"test"}
  142. #-------------------------------------------------------------------
  143. JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g"
  144. DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
  145. JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
  146. #-------------------------------------------------------------------
  147. startServer() {
  148. pid=$1
  149. if [ -z $pid ];then
  150. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  151. cd $dirPath
  152. 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"
  153. 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 &
  154. echo "$serverName 启动成功!"
  155. else
  156. echo "$serverName 正在运行..."
  157. fi
  158. echo "查看日志: tail -F $logPath -n 100"
  159. }
  160. stopServer() {
  161. pid=$1
  162. if [ -z $pid ];then
  163. echo "$serverName 未运行"
  164. else
  165. echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix"
  166. ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill
  167. echo "$serverName 已停止!"
  168. fi
  169. }
  170. pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
  171. if [ ! -z $pid ];then
  172. stopServer $pid
  173. sleep 3s
  174. fi
  175. startServer
  176. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/dsl/build.sh)