linux——jar包一键启动脚本

shell脚本

#!/bin/bash
JAR_NAME=bysj-admin.jar
 
tpid=`ps -ef|grep $JAR_NAME|grep -v grep|grep -v kill|awk {print $2}`
if [ ${tpid} ]; then
    echo Stop Process...
fi
sleep 5
tpid=`ps -ef|grep $JAR_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 $JAR_NAME|grep -v grep|grep -v kill|awk {print $2}`
if [ ${tpid} ]; then
            echo App is running.
    else
                echo App is NOT running.
        fi
 
        rm -f tpid
        
		#nohup java -jar ./$JAR_NAME --spring.profiles.active=test >/dev/null 2>&1 &
		# 开启远程调试 address为调试端口
		# nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar ./$JAR_NAME > ./debug.log 2>&1 &

        nohup java -jar ./$JAR_NAME  > ./bysj-admin-log.log 2>&1 &
        echo $! > tpid
        echo Start Success!

然后给该sh脚本赋予一下执行权限

chmod u+x xxx.sh
经验分享 程序员 微信小程序 职场和发展