.
目录
放置地址
启动脚本
停止脚本
放置地址
先说我的脚本地址:

脚本放置在bin目录下, logs 为日志目录.
启动脚本
启动脚本(start.sh),不多说,看脚本:
#!/bin/bash CURR_DIR=`dirname $0` cd $CURR_DIR if [ ! -d "../logs" ]; then mkdir ../logs fi rm -f tpid nohup java -jar ../test.jar --server.port=56789 --spring.profiles.active=dev 1>/dev/null 2>> ../logs/nohup-err.out & echo $! > tpid echo Project Start Success! tpid 存储的是当前启动的进程号!
停止脚本
停止脚本(stop.sh):
#!/bin/sh
APP_NAME=test.jar
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 'Project Stop Success!'
如此就可以执行脚本而启动或者关闭运行中的springboot项目. 而无需手动kill -9 去停止服务
