jenkins-server.sh 6.0 KB

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