linux-程序发布脚本

写了个启动程序, 调优jvm的脚本

#!/bin/bash

MEM=`free -m | grep Mem | awk '{print int($2 * 90 / 100)}'`

JAVA_OPTS="-server \
 -Xmx${MEM}m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=4\
 "

APP_HOME=`dirname $(pwd)`
APP_JAR_NAME="idfa.web-1.0.jar"
PID_FILE="$APP_HOME/pid.file"

pid=0

commond="$JAVA_OPTS -jar $APP_HOME/libs/$APP_JAR_NAME"
#commond="nohup java  -jar $APP_HOME/libs/$APP_JAR_NAME 1 >> $APP_HOME/nohup.log 2>&1 &"

getpid() {
    if [ -f "${PID_FILE}" ]; then
       pid=`cat ${PID_FILE}`
       echo "----------------------------------------"
       echo "pid file with ${pid}"
       echo "----------------------------------------"
       pid_count=`ps aux | grep idfa.web-1.0 | grep " ${pid} " | grep -v grep | wc -l`
       if [ ${pid_count} -eq 0 ]; then
          echo "${pid} dose not exist!"
          rm -rf ${PID_FILE}
          pid=0
       fi
    else
       pid=0
    fi
}

startup(){
    getpid
    echo "======================================="
    if [ ${pid} -ne 0 ]; then
        echo "${APP_JAR_NAME} already started(PID=${pid})"
        echo "======================================="
    else
        echo "Starting ${APP_JAR_NAME}"
        ulimit -c unlimited
        cd ${APP_HOME}

        echo $commond

        nohup java $commond &

        echo $! > ${PID_FILE}

    sleep 1

        getpid

        if [ ${pid} -ne 0 ]; then
            echo "(PID=${pid})...[Success]"
            echo "======================================="
        else
            echo "[Failed]"
            echo "======================================="
            exit -1
        fi
        cd -
    fi
}

shutdown(){
    getpid
    echo "======================================="
    if [ ${pid} -ne 0 ]; then
        echo "Stopping ${APP_JAR_NAME}(PID=${pid})..."
        kill -15 ${pid}
    getpid
    while [ ${pid} -ne 0 ]
    do
            sleep 1
            getpid
    done
    echo "[Success]"
    echo "======================================="
    else
        echo "${APP_JAR_NAME} is not running"
        echo "======================================="
    fi
}

shutdown_force(){
    getpid
    echo "======================================="
    if [ ${pid} -ne 0 ]; then
        echo "Stopping ${APP_JAR_NAME}(PID=${pid})..."
        kill -9 ${pid}
    getpid
    while [ ${pid} -ne 0 ]
    do
            sleep 1
            getpid
    done
    echo "[Success]"
    echo "======================================="
    else
        echo "${APP_JAR_NAME} is not running"
        echo "======================================="
    fi
}

status(){
    getpid
    echo "======================================="
    if [ ${pid} -ne 0 ]; then
        echo "${APP_JAR_NAME} is running(PID=${pid})"
        echo "======================================="
    else
        echo "${APP_JAR_NAME} is not running"
        echo "======================================="
    fi
}

case "$1" in
  start)
     startup
     ;;
  stop)
     shutdown
     ;;
  force)
     shutdown_force
     ;;
  restart)
     $0 stop
     sleep 1
     $0 start
     ;;
  status)
     status
     ;;
  *)
     exit 1
esac

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值