01wms83-test.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=/home/www/deploy/wms8_shengke
  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. "master"
  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_shengke/wms8_shengke.log
  99. dirPath=/home/www/deploy/wms8_shengke/wms-biz/servo/build/libs/
  100. serverName=wms8_shengke
  101. cmd=$1
  102. profiles=${2:-"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=8101 >>/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=8101 >>/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. start=$2
  148. deployPull
  149. buildCode
  150. echo "###--代码构建完成--------------------------------------------------------------------------###"
  151. # 停止服务
  152. if [ ! -z $pid ];then
  153. stopServer $pid
  154. sleep 8s
  155. fi
  156. # 移动编译后的文件
  157. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  158. cd $dirPath
  159. echo -e "$echoPrefix rm -rf ../runtime $echoSuffix"
  160. rm -rf ../runtime
  161. echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix"
  162. cp -r ./ ../runtime
  163. echo ""
  164. # 启动服务
  165. if [ "$start" == "start" ];then
  166. startServer
  167. fi
  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 build 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 build deploy restart start stop kill log logs"
  191. fi
  192. elif [ "$cmd" == "build" ];then
  193. deployYvanUI
  194. deployServer "$pid" "no_start"
  195. elif [ "$cmd" == "deploy" ];then
  196. deployYvanUI
  197. deployServer "$pid" "start"
  198. elif [ "$cmd" == "restart" ];then
  199. restartServer $pid
  200. elif [ "$cmd" == "start" ];then
  201. startServer $pid
  202. elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then
  203. stopServer $pid
  204. elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then
  205. logs
  206. else
  207. if [ -z $pid ];then
  208. echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs"
  209. echo "查看日志: tail -F $logPath -n 100"
  210. else
  211. echo "输入操作参数: pull build deploy restart start stop kill log logs"
  212. echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100"
  213. fi
  214. fi
  215. # 云南圣科
  216. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/05shengke/01wms83-test.sh) [cmd profiles]