01wms8-test.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=/home/www/deploy/wms8_dygk
  5. gitUrlArr=(
  6. "http://git.galaxis.yvanui.com/wms8/wms8-bench.git"
  7. "http://git.galaxis.yvanui.com/wms8/wms-core.git"
  8. "www@git.yvanui.com:lizhiwei/yvan-framework.git"
  9. ## "http://git.yvanui.com/lizhiwei/yvan-framework.git"
  10. )
  11. branchArr=(
  12. "dongying_guokang"
  13. "dongying_guokang"
  14. "master"
  15. )
  16. positionArr=(
  17. "."
  18. "wms-core"
  19. "yvan-framework"
  20. )
  21. # 是否需要构建,-1:自动;0:不需要;1:需要
  22. needBuild=(
  23. "1"
  24. "1"
  25. "1"
  26. )
  27. echoPrefix="\033[36m+"
  28. echoSuffix="\033[0m"
  29. # 强制覆盖本地的代码 git fetch --all && git reset --hard origin/master
  30. isChange="1" # 仓库是否发生变化,0:未变化;非0:变化
  31. pullCode() {
  32. # Usage: pullCode "codePath" "gitUrl" "branch" "position"
  33. path=$1 # 代码保存路径
  34. gitUrl=$2 # git仓库地址
  35. branch=${3:-"master"} # git分支
  36. position=${4:-""} # 使用“.”clone到当前文件夹
  37. isChange="1"
  38. # 创建文件夹
  39. if [ ! -d "$path" ]; then
  40. echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix"
  41. exit
  42. fi
  43. # git clone
  44. echo -e "$echoPrefix cd $path $echoSuffix"
  45. cd $path
  46. if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then
  47. echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix"
  48. git clone $gitUrl $position
  49. isChange="2"
  50. fi
  51. # 进入文件夹,切换分支,git pull
  52. if [ "$position" != "" ]; then
  53. echo -e "$echoPrefix cd $position $echoSuffix"
  54. cd $position
  55. fi
  56. echo -e "$echoPrefix git checkout $branch $echoSuffix"
  57. git checkout $branch
  58. echo -e "$echoPrefix git checkout . $echoSuffix"
  59. git checkout .
  60. echo -e "$echoPrefix git pull $echoSuffix"
  61. if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then
  62. isChange="0"
  63. fi
  64. echo ""
  65. }
  66. buildCode() {
  67. # 构建 wms-biz/bundle
  68. if [ "${needBuild[0]}" != "0" ]; then
  69. echo -e "$echoPrefix cd $codePath/wms-biz/bundle $echoSuffix"
  70. cd "$codePath/wms-biz/bundle"
  71. echo -e "$echoPrefix yarn $echoSuffix"
  72. yarn
  73. echo -e "$echoPrefix yarn link yvan-ext $echoSuffix"
  74. yarn link yvan-ext
  75. echo -e "$echoPrefix yarn build $echoSuffix"
  76. yarn build
  77. echo ""
  78. else
  79. echo "wms-biz/bundle 文件未变化"
  80. fi
  81. # 构建 wms-biz/pda-client
  82. if [ "${needBuild[0]}" != "0" ]; then
  83. echo -e "$echoPrefix cd $codePath/wms-biz/pda-client $echoSuffix"
  84. cd "$codePath/wms-biz/pda-client"
  85. echo -e "$echoPrefix yarn $echoSuffix"
  86. yarn
  87. echo -e "$echoPrefix yarn link yvan-ext-mobile $echoSuffix"
  88. yarn link yvan-ext-mobile
  89. echo -e "$echoPrefix yarn build $echoSuffix"
  90. yarn build
  91. echo ""
  92. else
  93. echo "wms-biz/pda-client 文件未变化"
  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. logPath=/data/logs/wms8_dygk/wms8_dygk.log
  103. dirPath=/home/www/deploy/wms8_dygk/wms-biz/servo/build/libs/
  104. serverName=wms8_dygk
  105. cmd=$1
  106. profiles=${2:-"test"}
  107. #-------------------------------------------------------------------
  108. JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g"
  109. DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
  110. JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
  111. #-------------------------------------------------------------------
  112. startServer() {
  113. pid=$1
  114. if [ -z $pid ];then
  115. echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix"
  116. cd $dirPath../runtime/
  117. echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8096 >>/dev/null 2>&1 & $echoSuffix"
  118. java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./servo-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8096 >>/dev/null 2>&1 &
  119. echo "$serverName 启动成功!"
  120. else
  121. echo "$serverName 正在运行..."
  122. fi
  123. echo "查看日志: tail -F $logPath -n 100"
  124. }
  125. stopServer() {
  126. pid=$1
  127. if [ -z $pid ];then
  128. echo "$serverName 未运行"
  129. else
  130. echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix"
  131. ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill
  132. echo "$serverName 已停止!"
  133. fi
  134. }
  135. deployPull() {
  136. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  137. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  138. if [ "${needBuild[idx]}" == "-1" ]; then
  139. needBuild[idx]=$isChange
  140. fi
  141. done
  142. # 设置 require_config.js 前端版本
  143. version=$(date +_%Y_%m_%d_%H_%M_%S)
  144. echo -e "$echoPrefix sed -i 's/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g' $codePath/public/require_config.js $echoSuffix"
  145. sed -i "s/_[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/$version/g" $codePath/public/require_config.js
  146. echo "###--代码更新完成--------------------------------------------------------------------------###"
  147. echo ""
  148. }
  149. deployServer() {
  150. pid=$1
  151. deployPull
  152. buildCode
  153. echo "###--代码构建完成--------------------------------------------------------------------------###"
  154. # 重启服务
  155. if [ ! -z $pid ];then
  156. stopServer $pid
  157. sleep 3s
  158. fi
  159. # 移动编译后的文件
  160. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  161. cd $dirPath
  162. echo -e "$echoPrefix rm -rf ../runtime $echoSuffix"
  163. rm -rf ../runtime
  164. echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix"
  165. cp -r ./ ../runtime
  166. echo ""
  167. startServer
  168. }
  169. restartServer() {
  170. pid=$1
  171. if [ ! -z $pid ];then
  172. stopServer $pid
  173. sleep 3s
  174. fi
  175. startServer
  176. }
  177. logs() {
  178. tail -F $logPath -n 100
  179. }
  180. deployYvanUI() {
  181. bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull
  182. bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull
  183. }
  184. pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
  185. # 操作参数: pull deploy restart start stop kill log logs
  186. if [ "$cmd" == "pull" ];then
  187. deployYvanUI
  188. deployPull
  189. if [ -z $pid ];then
  190. echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs"
  191. fi
  192. elif [ "$cmd" == "deploy" ];then
  193. deployYvanUI
  194. deployServer $pid
  195. elif [ "$cmd" == "restart" ];then
  196. restartServer $pid
  197. elif [ "$cmd" == "start" ];then
  198. startServer $pid
  199. elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then
  200. stopServer $pid
  201. elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then
  202. logs
  203. else
  204. if [ -z $pid ];then
  205. echo "$serverName 未运行 | 输入操作参数: pull deploy restart start stop kill log logs"
  206. else
  207. echo "输入操作参数: pull deploy restart start stop kill log logs"
  208. echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100"
  209. fi
  210. fi
  211. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/01dongying_guokang/01wms8-test.sh) [cmd profiles]