06wms8-test2.sh 7.0 KB

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