dashenlin-naning-prd_build.sh 5.8 KB

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