Spring boot部署脚本

简介

Spring boot程序需要打成jar包在Linux上后台运行,维护比较困难,所以找到了以下脚本,可以存储java程序的pid到文件中去,方便停止和查看状态
注意:这是比较原始的部署方式了,现在已经使用Docker方式部署了,详见另一篇博文:多环境jar部署脚本示例

start.sh

1
2
3
4
5
6
7
#!/bin/sh

rm -f tpid

nohup java -jar -Dspring.profiles.active=profileName -Xms512m -Xmx2048m myapp.jar --spring.config.location=application.yml > /dev/null 2>&1 &echo $! > tpid

echo Start Success!

stop.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
APP_NAME=myapp

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

1
2
3
4
5
6
7
8
9
#!/bin/sh
APP_NAME=myapp

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

kill.sh

1
2
3
4
5
6
7
8
#!/bin/sh
APP_NAME=myapp

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
fi
文章目录
  1. 1. 简介
    1. 1.1. start.sh
    2. 1.2. stop.sh
    3. 1.3. check.sh
    4. 1.4. kill.sh