springboot Jar包 部署到Linux服务器运行脚本

1、jar包同级目录  如下:

#!/bin/sh
RESOURCE_NAME=demo.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 'App is running.'
else
    echo 'App is NOT running.'
fi
rm -f tpid
nohup java -jar ./$RESOURCE_NAME --spring.profiles.active=test &
echo $! > tpid
echo Start Success!

2、脚本运行   

cd /demo (我是把jar包和脚本放在home下面)

chmod +x start.sh (第一次运行的时候获取一下超级管理员权限)

然后以后每次运行直接

./start.sh 即可

拷贝脚本的时候运行的时候如果报错,应该是文件格式转换的问题

bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory

可以  yum -y install dos2unix  

然后 dos2unix start.sh 

重新运行脚本

原文地址:https://www.cnblogs.com/sunshouguo/p/10812831.html