linux-程序发布脚本

Posted bronk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

 

以上是关于linux-程序发布脚本的主要内容,如果未能解决你的问题,请参考以下文章

jsp

常用python日期日志获取内容循环的代码片段

如何在 Toad for Oracle 中使用自定义代码片段?

JSP语法

ASP.net MVC 代码片段问题中的 Jqgrid 实现

代码片段:Shell脚本实现重复执行和多进程