123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #!/bin/bash
- # jenkins远程执行脚本重启微服务
- BASEDIR="/mdata/cooleshow-test/jenkins"
- CURRENT_DIR=`pwd`
- PROFILE_ACTIVE="test"
- # 停止服务
- function shutdown() {
- SERVER_ID=$(netstat -antp | grep :$2 | grep LISTEN | awk '{print $7}' | awk -F/ '{ print $1 }')
- if [ -n "$SERVER_ID" ]; then
- kill -9 $SERVER_ID
- echo "starting kill -9 $2...($1)"
- fi
- }
- function mkdirs() {
- LOG_PATH=$1
- if [ ! -x "$LOG_PATH" ]; then
- mkdir -p $LOG_PATH
- fi
- }
- function test() {
- echo "test $*"
- }
- function gateway-server() {
-
- shutdown $1 8000
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/gateway-web.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function auth-server() {
- shutdown $1 8001
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/auth-server.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function admin-server() {
- shutdown $1 8005
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/user-admin.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function teacher-server() {
-
- shutdown $1 9002
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/user-teacher.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function student-server() {
-
- shutdown $1 9001
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/user-student.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function website-server() {
-
- shutdown $1 8020
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/user-website.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function websocket-server() {
-
- shutdown $1 9010
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/cooleshow-websocket.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function audio-analysis() {
-
- shutdown $1 9004
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/audio-analysis.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function bbs-server() {
- shutdown $1 8012
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/cooleshow-bbs.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy bbs-server"
- }
- function task-server() {
- shutdown $1 8009
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/cooleshow-task.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy task-server"
- }
- function classroom-server() {
-
- shutdown $1 9999
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/user-classroom.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function cms-server() {
-
- shutdown $1 8006
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/cooleshow-cms.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function tenant-server() {
- shutdown $1 8021
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/user-tenant.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function mall-admin() {
-
- shutdown $1 8010
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/mall-admin.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function mall-server() {
-
- shutdown $1 8011
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/mall-portal.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- function app-server() {
- shutdown $1 8022
- nohup java -jar -Dspring.profiles.active=${PROFILE_ACTIVE} \
- -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m \
- ${CURRENT_DIR}/libs/cooleshow-app.jar > ${BASEDIR}/logs/$1/stdout.log 2>&1 &
- echo "completed deploy $1"
- }
- if [ $# -le 0 ]; then
- # 解压文件
- tar -zxf *.tar.gz
- echo "tar -xvf *.tar.gz"
- SERVICE_NAME=${CURRENT_DIR}/libs/service.md
- # 服务名称匹配,重启服务
- while read LINE; do
- if [[ ${LINE:3:1} != 'x' ]]; then
- # 不需要重启服务,直接忽略跳过
- continue
- fi
- SERVICE=${LINE:6}
- #日志目录
- LOG_PATH=${BASEDIR}/logs/${SERVICE}
- mkdirs $LOG_PATH
- # 调用函数
- $SERVICE $SERVICE
-
- echo "--------------${SERVICE}-----------------"
- done < ${SERVICE_NAME}
- else
- SERVICE_NAME="exit \
- gateway-server auth-server admin-server \
- teacher-server student-server website-server websocket-server \
- audio-analysis bbs-server classroom-server cms-server \
- mall-admin mall-server task-server tenant-server app-server"
- select SERVICE in ${SERVICE_NAME}; do
- # 退出
- if [[ $SERVICE == 'exit' ]]; then
- break
- fi
- #日志目录
- LOG_PATH=${BASEDIR}/logs/${SERVICE}
- mkdirs $LOG_PATH
- #调用函数
- $SERVICE $SERVICE
- echo "--------------${SERVICE}-----------------"
- done
- fi
|