启动脚本

#!/bin/sh
RESOURCE_NAME=atlas-oss-0.0.1-SNAPSHOT.jar

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

tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'atlas-oss is running.'
else
    echo 'atlas-oss is NOT running.'
fi

rm -f tpid
nohup java -jar $RESOURCE_NAME --spring.profiles.active=oss-dev &
echo $! > tpid
echo Start Success!

升级版本

#!/usr/bin/env bash

binDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ${binDir} && cd ../
curDir=`pwd`
#binDir="$( cd $(dirname $0) && pwd )"
#curDir="$( cd $(dirname $binDir); pwd )"
packageName=${curDir##*/}
moduleName=${packageName%-*}

if [ ! -n "$PRO_PATH" ]; then
    export PRO_PATH="${curDir}"
fi

profiles=$2
rootDir=${curDir}
libPath=${rootDir}/lib
libPathCustomize=${rootDir}/libcustomize
sourcePath=${rootDir}/conf
export logPath=${rootDir}/logs
stopPath=${rootDir%-*}

if [ ! -d ${logPath} ]; then
    mkdir -p ${logPath}
fi

start() {
    echo "start ${moduleName}..."
    nohup java -Dloader.path=${libPathCustomize},${libPath},${sourcePath} -XX:+UseConcMarkSweepGC 
    -DJM.LOG.PATH=${logPath} -DJM.SNAPSHOT.PATH=${sourcePath} 
    -Xmx2048m -Xms2048m -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:${logPath}/java_gc.log 
    -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Duser.timezone=Asia/Shanghai 
    -XX:-HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${logPath} -jar ${libPath}/${packageName}.jar 
    --spring.profiles.active=${profiles} --isJar=true > /dev/null 2>&1 &
}

stop() {
    pid=`ps -ef | grep ${stopPath} | grep -v grep | awk '{print $2}'`
    echo "stop ${moduleName}..."
    if [ -n "${pid}" ]
    then
        kill -9 $pid
    fi
}

restart() {
    stop
    start
}

case "$1" in
    start|stop|restart)
          case "$2" in
              haizhi|test|uat)
                  $1
                  ;;
              *)
                  echo $"Usage: $0 {start|stop|restart} {haizhi|test|uat}"
                  exit 2
          esac
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
原文地址:https://www.cnblogs.com/yadongliang/p/13955240.html