prod-deploy-his-data.sh 7.8 KB

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