运行脚本

#!/bin/sh
#
#
### 配置路径
APP_DIR=.
#//配置名称
APP_NAME=api-gateway-1.0.0.RELEASE
PORT=9091

usage() {
    echo "Usage: sh run.sh [start|stop|deploy]"
    exit 1
}

kills(){
    tpid=`ps -ef|grep $PORT|grep -v grep|grep -v kill|awk '{print $2}'`
    if [[ $tpid ]]; then
        echo 'Kill Process!'
        kill -9 $tpid
    fi
}

start(){
    rm -f $APP_DIR/tpid
    nohup java -Xms200m -Xmx200m -XX:PermSize=356m -XX:MaxPermSize=500m -XX:MaxNewSize=500m -jar -Dspring.config.location=./application.yml -Dserver.port=$PORT $APP_DIR/"$APP_NAME".jar > logs.log 2>&1 &
    echo $! > $APP_DIR/tpid
    echo Start Success!
}

stop(){
        tpid1=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
    echo tpid1-$tpid1
        if [[ $tpid1 ]]; then
        echo 'Stop Process...'
        kill -15 $tpid1
    fi
    sleep 5
    tpid2=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
        echo tpid2-$tpid2
    if [[ $tpid2 ]]; then
        echo 'Kill Process!'
        kill -9 $tpid2
    else
        echo 'Stop Success!'
    fi

}

check(){
    tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
    if [[ tpid ]]; then
        echo 'App is running.'
    else
        echo 'App is NOT running.'
    fi
}

deploy() {
    kills
    rm -rf $APP_DIR/"$APPNAME".jar
    cp "$APP_NAME".jar $APP_DIR
}

case "$1" in
    "start")
        start
        ;;
    "stop")
        stop
        ;;
    "kill")
        kills
        ;;
    "check")
        check
        ;;
    *)
        usage
        ;;
esac

results matching ""

    No results matching ""