jar包重啓腳本-restart.sh

#!/bin/sh
PROJECT_PATH=/var/www/
PROJECT_NAME=demo.jar
PROJECT_ALL_LOG_NAME=logs/demo-all.log
# stop process
tpid=`ps -ef|grep $PROJECT_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 $PROJECT_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi

# start process
tpid=`ps -ef|grep $PROJECT_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'App is already running.'
else
    echo 'App is NOT running.'

    nohup java -jar $PROJECT_PATH$PROJECT_NAME >/dev/null 2>&1 &
    echo Start Success!
    sleep 2
    tail -f $PROJECT_PATH$PROJECT_ALL_LOG_NAME
fi
相關文章
相關標籤/搜索