08wms-ztf--configcenter-test.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #!/bin/bash
  2. #set -x
  3. set -e
  4. codePath=/home/www/deploy/wms8_ztf_config_center_2
  5. gitUrlArr=(
  6. "http://git.yvanui.com/jztd/wms.git"
  7. "http://git.yvanui.com/jztd/wms-ui-config-center.git"
  8. "http://git.yvanui.com/lizhiwei/yvan-framework.git"
  9. )
  10. branchArr=(
  11. "master"
  12. "master"
  13. "8.4"
  14. )
  15. positionArr=(
  16. "."
  17. "wms-modules/wms-ui-config-center"
  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-ui-pc
  67. if [ "${needBuild[1]}" != "0" ]; then
  68. echo -e "$echoPrefix cd $codePath/wms-ui-pc $echoSuffix"
  69. cd "$codePath/wms-ui-pc"
  70. echo -e "$echoPrefix yarn $echoSuffix"
  71. yarn
  72. echo -e "$echoPrefix yarn link yvan-vue $echoSuffix"
  73. yarn link yvan-vue
  74. echo ""
  75. else
  76. echo "wms-ui-pc 文件未变化"
  77. fi
  78. # 构建 wms-ui-mobile
  79. if [ "${needBuild[2]}" != "0" ]; then
  80. echo -e "$echoPrefix cd $codePath/wms-ui-mobile $echoSuffix"
  81. cd "$codePath/wms-ui-mobile"
  82. echo -e "$echoPrefix yarn $echoSuffix"
  83. yarn
  84. echo -e "$echoPrefix yarn link yvan-vue-mobile $echoSuffix"
  85. yarn link yvan-vue-mobile
  86. echo ""
  87. else
  88. echo "wms-ui-mobile 文件未变化"
  89. fi
  90. # 构建 java
  91. echo -e "$echoPrefix cd $codePath $echoSuffix"
  92. cd $codePath
  93. echo -e "$echoPrefix gradle build -x test $echoSuffix"
  94. gradle build -x test
  95. echo ""
  96. }
  97. logPath=/data/logs/config-center/server.log
  98. dirPath=/home/www/deploy/config-center/wms-modules/wms-config-center/build/libs/
  99. serverName=2_wms8_ztf_config_center_2
  100. cmd=$1
  101. profiles=${2:-"test"}
  102. #-------------------------------------------------------------------
  103. JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx2g -Xms2g"
  104. DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
  105. JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
  106. #-------------------------------------------------------------------
  107. moveBuildFile() {
  108. # 移动编译后的文件
  109. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  110. cd $dirPath
  111. echo -e "$echoPrefix rm -rf ../runtime $echoSuffix"
  112. rm -rf ../runtime
  113. echo -e "$echoPrefix cp -r ./ ../runtime $echoSuffix"
  114. cp -r ./ ../runtime
  115. echo ""
  116. }
  117. startServer() {
  118. pid=$1
  119. if [ -z $pid ];then
  120. echo -e "$echoPrefix cd $dirPath../runtime/ $echoSuffix"
  121. cd $dirPath../runtime/
  122. echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./wms-config-center-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8083 >>/dev/null 2>&1 & $echoSuffix"
  123. java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./wms-config-center-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=8083 >>/dev/null 2>&1 &
  124. echo "$serverName 启动成功!"
  125. else
  126. echo "$serverName 正在运行..."
  127. fi
  128. echo "查看日志: tail -F $logPath -n 100"
  129. }
  130. stopServer() {
  131. pid=$1
  132. if [ -z $pid ];then
  133. echo "$serverName 未运行"
  134. else
  135. echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix"
  136. ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill
  137. echo "$serverName 已停止!"
  138. fi
  139. }
  140. deployPull() {
  141. for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do
  142. pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]}
  143. if [ "${needBuild[idx]}" == "-1" ]; then
  144. needBuild[idx]=$isChange
  145. fi
  146. done
  147. # 设置 require_config.js 前端版本
  148. # version=$(date +_%Y_%m_%d_%H_%M_%S)
  149. # 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"
  150. # 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
  151. echo "###--代码更新完成--------------------------------------------------------------------------###"
  152. echo ""
  153. }
  154. deployServer() {
  155. pid=$1
  156. deployPull
  157. buildCode
  158. echo "###--代码构建完成--------------------------------------------------------------------------###"
  159. # 重启服务
  160. if [ ! -z $pid ];then
  161. stopServer $pid
  162. sleep 8s
  163. fi
  164. # 移动编译后的文件
  165. moveBuildFile
  166. startServer
  167. }
  168. restartServer() {
  169. pid=$1
  170. if [ ! -z $pid ];then
  171. stopServer $pid
  172. sleep 3s
  173. fi
  174. moveBuildFile
  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/11yvan-vue.sh) deploy
  182. }
  183. startPcUi() {
  184. pid=`ps -ef | grep "${codePath}/wms-modules/wms-ui-config-center/node_modules/.bin/vite" | grep -v 'grep' | awk '{print $2}'`
  185. if [ -z $pid ];then
  186. echo "wms-ui-config-center 未运行"
  187. else
  188. echo -e "$echoPrefix ps -ef | grep "${codePath}/wms-modules/wms-ui-config-center/node_modules/.bin/vite" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix"
  189. ps -ef | grep "${codePath}/wms-modules/wms-ui-config-center/node_modules/.bin/vite" | grep -v 'grep' | awk '{print $2}' | xargs kill
  190. echo "wms-ui-config-center 已停止!"
  191. sleep 3s
  192. fi
  193. echo -e "$echoPrefix cd $codePath/wms-modules/wms-ui-config-center $echoSuffix"
  194. cd "$codePath/wms-modules/wms-ui-config-center"
  195. echo -e "$echoPrefix nohup yarn run dev >>/dev/null 2>&1 & $echoSuffix"
  196. nohup yarn run dev >>/dev/null 2>&1 &
  197. }
  198. pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
  199. # 操作参数: pull build deploy restart start stop kill log logs startPc
  200. if [ "$cmd" == "pull" ];then
  201. deployYvanUI
  202. deployPull
  203. if [ -z $pid ];then
  204. echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs startPc"
  205. fi
  206. elif [ "$cmd" == "build" ];then
  207. deployYvanUI
  208. deployPull
  209. buildCode
  210. echo "###--代码构建完成--------------------------------------------------------------------------###"
  211. elif [ "$cmd" == "deploy" ];then
  212. deployYvanUI
  213. deployServer $pid
  214. startPcUi
  215. elif [ "$cmd" == "restart" ];then
  216. restartServer $pid
  217. elif [ "$cmd" == "start" ];then
  218. startServer $pid
  219. elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then
  220. stopServer $pid
  221. elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then
  222. logs
  223. elif [ "$cmd" == "startPc" ];then
  224. startPcUi
  225. else
  226. if [ -z $pid ];then
  227. echo "$serverName 未运行 | 输入操作参数: pull build deploy restart start stop kill log logs startPc"
  228. echo "查看日志: tail -F $logPath -n 100"
  229. else
  230. echo "输入操作参数: pull build deploy restart start stop kill log logs startPc"
  231. echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100"
  232. fi
  233. fi
  234. # 中通服-配置中台-华为云-测试
  235. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/hua_wei_yun/08wms-ztf--configcenter-test.sh) [cmd profiles]