jenkins-server.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/bin/bash
  2. # jenkins远程执行脚本重启微服务
  3. BASEDIR="/mdata/cooleshow-test/jenkins"
  4. CURRENT_DIR=`pwd`
  5. PROFILE_ACTIVE="test"
  6. # 停止服务
  7. function shutdown() {
  8. SERVER_ID=$(netstat -antp | grep :$2 | grep LISTEN | awk '{print $7}' | awk -F/ '{ print $1 }')
  9. if [ -n "$SERVER_ID" ]; then
  10. kill -9 $SERVER_ID
  11. echo "starting kill -9 $2...($1)"
  12. fi
  13. }
  14. function mkdirs() {
  15. LOG_PATH=$1
  16. if [ ! -x "$LOG_PATH" ]; then
  17. mkdir -p $LOG_PATH
  18. fi
  19. }
  20. function test() {
  21. echo "test $*"
  22. }
  23. function gateway-server() {
  24. shutdown $1 8000
  25. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  26. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  27. ${CURRENT_DIR}/libs/gateway-web.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  28. echo "completed deploy $1"
  29. }
  30. function auth-server() {
  31. shutdown $1 8001
  32. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  33. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  34. ${CURRENT_DIR}/libs/auth-server.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  35. echo "completed deploy $1"
  36. }
  37. function admin-server() {
  38. shutdown $1 8005
  39. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  40. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  41. ${CURRENT_DIR}/libs/user-admin.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  42. echo "completed deploy $1"
  43. }
  44. function teacher-server() {
  45. shutdown $1 9002
  46. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  47. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  48. ${CURRENT_DIR}/libs/user-teacher.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  49. echo "completed deploy $1"
  50. }
  51. function student-server() {
  52. shutdown $1 9001
  53. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  54. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  55. ${CURRENT_DIR}/libs/user-student.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  56. echo "completed deploy $1"
  57. }
  58. function website-server() {
  59. shutdown $1 8020
  60. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  61. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  62. ${CURRENT_DIR}/libs/user-website.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  63. echo "completed deploy $1"
  64. }
  65. function websocket-server() {
  66. shutdown $1 9010
  67. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  68. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  69. ${CURRENT_DIR}/libs/cooleshow-websocket.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  70. echo "completed deploy $1"
  71. }
  72. function audio-analysis() {
  73. shutdown $1 9004
  74. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  75. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  76. ${CURRENT_DIR}/libs/audio-analysis.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  77. echo "completed deploy $1"
  78. }
  79. function bbs-server() {
  80. shutdown $1 8012
  81. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  82. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  83. ${CURRENT_DIR}/libs/cooleshow-bbs.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  84. echo "completed deploy bbs-server"
  85. }
  86. function task-server() {
  87. shutdown $1 8009
  88. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  89. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  90. ${CURRENT_DIR}/libs/cooleshow-task.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  91. echo "completed deploy task-server"
  92. }
  93. function classroom-server() {
  94. shutdown $1 9999
  95. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  96. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  97. ${CURRENT_DIR}/libs/user-classroom.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  98. echo "completed deploy $1"
  99. }
  100. function cms-server() {
  101. shutdown $1 8006
  102. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  103. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  104. ${CURRENT_DIR}/libs/cooleshow-cms.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  105. echo "completed deploy $1"
  106. }
  107. function tenant-server() {
  108. shutdown $1 8021
  109. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  110. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  111. ${CURRENT_DIR}/libs/user-tenant.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  112. echo "completed deploy $1"
  113. }
  114. function mall-admin() {
  115. shutdown $1 8010
  116. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  117. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  118. ${CURRENT_DIR}/libs/mall-admin.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  119. echo "completed deploy $1"
  120. }
  121. function mall-server() {
  122. shutdown $1 8011
  123. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  124. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  125. ${CURRENT_DIR}/libs/mall-portal.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  126. echo "completed deploy $1"
  127. }
  128. function app-server() {
  129. shutdown $1 8022
  130. nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
  131. -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
  132. ${CURRENT_DIR}/libs/cooleshow-app.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
  133. echo "completed deploy $1"
  134. }
  135. if [ $# -le 0 ]; then
  136. # 解压文件
  137. tar -zxf *.tar.gz
  138. echo "tar -xvf *.tar.gz"
  139. SERVICE_NAME=${CURRENT_DIR}/libs/service.md
  140. # 服务名称匹配,重启服务
  141. while read LINE; do
  142. if [[ ${LINE:3:1} != 'x' ]]; then
  143. # 不需要重启服务,直接忽略跳过
  144. continue
  145. fi
  146. SERVICE=${LINE:6}
  147. #日志目录
  148. LOG_PATH=${BASEDIR}/logs/${SERVICE}
  149. mkdirs $LOG_PATH
  150. # 调用函数
  151. $SERVICE $SERVICE
  152. echo "--------------${SERVICE}-----------------"
  153. done < ${SERVICE_NAME}
  154. else
  155. SERVICE_NAME="exit \
  156. gateway-server auth-server admin-server \
  157. teacher-server student-server website-server websocket-server \
  158. audio-analysis bbs-server classroom-server cms-server \
  159. mall-admin mall-server task-server tenant-server app-server"
  160. select SERVICE in ${SERVICE_NAME}; do
  161. # 退出
  162. if [[ $SERVICE == 'exit' ]]; then
  163. break
  164. fi
  165. #日志目录
  166. LOG_PATH=${BASEDIR}/logs/${SERVICE}
  167. mkdirs $LOG_PATH
  168. #调用函数
  169. $SERVICE $SERVICE
  170. echo "--------------${SERVICE}-----------------"
  171. done
  172. fi