01wms-hwy-test.sh 7.0 KB

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