spring cloud 微服务启动脚本

#!/bin/bash
APP_NAME=xxx
JAR_FILE=$APP_NAME.jar
LOG_PATH=/home/chen/logs/log

start(){
  checkpid
  if [ ! -n "$pid" ]; then
    echo "启动命令"
    echo "nohup java -jar $JAR_FILE >nohup.out &"
    nohup java -jar $JAR_FILE  >nohup.out &
    echo "---------------------------------"
    echo "启动完成,按CTRL+C退出日志界面即可>>>>>"
    echo "---------------------------------"
    sleep 35s
    # 到日志文件夹中寻找最新的一个日志文件
    LOG_FILE=`ls -t $LOG_PATH/idcim.log | head -1`
    # 打印启动日志,如果发现日志中包含Tomcat started这个字符说明启动成功,结束打印进程
    tail -f $LOG_FILE|while read line
    do
        kw=`echo $line|grep "Tomcat started"|wc -l`
        if [ $kw -lt 1 ];then
            echo $line
        else
        tail_pid=`ps -ef |grep $LOG_FILE |grep -v grep |awk '{print $2}'`
        kill -9 $tail_pid
        fi
    done
    echo "执行成功"
  else
      echo "$APP_NAME is runing PID: $pid"
  fi
}

checkpid(){
    pid=`ps -ef |grep $JAR_FILE |grep -v grep |awk '{print $2}'`
}

stop(){
     # 停止前直接到对应的eureka服务中删除对应的实例,URL规则可以根据注册时的不同规则自行制定
      #curl -X "DELETE"  "http://$EUREKA_HOST/eureka/apps/$APP/$server:$PORT"
    checkpid
    if [ ! -n "$pid" ]; then
     echo "$APP_NAME not runing"
    else
      echo "$APP_NAME stop..."
      kill $pid
      sleep 2s
      kill -9 $pid
    fi
}
 
restart(){
    stop
    sleep 1s
    start
}
 
status(){
   checkpid
   if [ ! -n "$pid" ]; then
     echo "$APP_NAME not runing"
   else
     echo "$APP_NAME runing PID: $pid"
   fi
}
case $1 in
          start) start;;
          stop)  stop;;
          restart)  restart;;
          status)  status;;
              *)  echo "require start|stop|restart|status"  ;;
esac

分享一个启动spring cloud微服务的脚本,在网上看的,然后修改的。更加简洁,方便使用。使用时修改APP_NAME和LOG_PATH

posted @ 2019-07-16 16:21  皇后  阅读(2155)  评论(0编辑  收藏  举报