zoukankan      html  css  js  c++  java
  • & SpringBoot启动脚本

    SpringBoot启动脚本记录

    #!/bin/sh
    
    ###
    
    #jar包名称
    SERVICE_NAME="cus"
    
    #上一级目录的env文件(指定启动环境dev/test/prod/uat)
    ENVFILE="../env"
    
    #同级目录的pid文件(写入进程id)
    PIDFILE="pid"
    
    checkRunning(){
        if [ -f "$PIDFILE" ]; then
           if  [ -z "`cat $PIDFILE`" ];then
            echo "ERROR: Pidfile '$PIDFILE' exists but contains no pid"
            return 2
           fi
           PID="`cat ${PIDFILE}`"
           RET="`ps -p "${PID}"|grep java`"
           if [ -n "$RET" ];then
             return 0;
           else
             return 1;
           fi
        else
             return 1;
        fi
    }
    
    status(){
        if ( checkRunning );then
             PID="`cat $PIDFILE`"
             echo "'$SERVICE_NAME' is running (pid '$PID')"
             exit 0
        fi
        echo "'$SERVICE_NAME' not running"
        exit 1
    }
    
    
    #start
    start(){
        if ( checkRunning );then
          PID="`cat $PIDFILE`"
          echo "INFO: Process with pid '$PID' is already running"
          exit 0
        fi
        ENVIRONMENT="`cat ${ENVFILE}`"
        java -jar ${SERVICE_NAME}.jar --spring.profiles.active=${ENVIRONMENT} > console.log 2>&1 &
        echo $! > "${PIDFILE}";
    }
    #Í£Ö¹·½·¨
    stop(){
        if ( checkRunning ); then
           PID="`cat ${PIDFILE}`"
           echo "INFO: sending SIGKILL to pid '$PID'"
           kill -KILL $PID
           RET="$?"
           rm -f "${PIDFILE}"
           return $RET
        fi
        echo "INFO: not running, nothing to do"
        return 0
    }
    
    show_help() {
        cat << EOF
    Tasks provided by the sysv init script:
        stop            - terminate instance in a drastic way by sending SIGKILL
        start           - start new instance
        restart         - stop running instance (if there is one), start new instance
        status          - check if '$SERVICE_NAME' process is running
    EOF
      exit 1
    }
    
    # show help
    if [ -z "$1" ];then
    show_help
    fi
    
    case "$1" in
      status)
        status
        ;;
      restart)
        stop
        start
        status
        ;;
      start)
        start
        ;;
      stop)
        stop
        exit $?
        ;;
      *)
    esac
    
  • 相关阅读:
    Collections和Arrays常用方法
    集合(三)------双列集合
    集合(二)------单列集合
    集合(一)----------概述
    泛型
    线程
    Math类和Random类(数学公式相关类)
    时间相关的类
    Runtime类及其常用方法
    第65题:有效数字
  • 原文地址:https://www.cnblogs.com/doagain/p/15015078.html
Copyright © 2011-2022 走看看