SpringBoot打包的程序部署到服务器后一直在后台运行

一般是:java -jar test.jar发现这个命令在关闭窗口后就停止了

nohup java -jar **.jar &

nohup命令可以不挂断的执行,忽略所有挂断信号,运行后,最后加&会在jar目录下生成nohup.out的日志文件,默认的log输出到这里了。

下面是从网上找一些的脚本

启动脚本start.sh

#!/bin/sh
rm -f tpid
nohup java -jar /var/apps/mytest.jar --spring.config.location=application.yml > /dev/null 2>&1 &
echo $! > tpid
echo Start Success!

停止服务 stop.sh

#!/bin/sh
APP_NAME=mytest
tpid=`ps -ef|grep $APP_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 $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi

检查状态check.sh

#!/bin/sh
APP_NAME=mytest
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
        echo 'App is running.'
else
        echo 'App is NOT running.'
fi

猜你喜欢

转载自blog.csdn.net/qq_38217873/article/details/80723247