build.sh 4.7 KB

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