SpringBoot项目启动脚本
以自己创建的项目invoice为例,linux服务器新建一个invoice目录,目录底下包括:
1、invoice.war(启动包) 2、logs文件夹(日志存放目录)3、nohup.out(启动日志) 4、run.sh 5、shutdown.sh 6、start.sh
shutdown.sh脚本内容
#!/bin/sh
APP_NAME=invoice.war
curl -X POST http://172.30.12.21:5002/actuator/shutdown
sleep 5
tpid1=`ps -ef|grep ${APP_NAME}|grep -v grep|grep -v kill|awk "{print $2}"`
echo tpid1-$tpid1
if [[ $tpid1 ]]; then
echo "Stop Process..."
kill -15 $tpid1
fi
sleep 5
tpid2=`ps -ef|grep ${APP_NAME}|grep -v grep|grep -v kill|awk "{print $2}"`
echo tpid2-$tpid2
if [[ $tpid2 ]]; then
echo "Kill Process!"
kill -9 $tpid2
else
echo "Stop Success!"
fi
run.sh脚本
#!/bin/sh
export LANG=en_US.UTF-8
export JAVA_HOME=/jdk18
export PATH=$JAVA_HOME/bin:$PATH
APP_PATH=$(cd `dirname $0`; pwd)
APP_NAME=invoice.war
datenow=$(date +%Y%m%d-%H%M%S)
echo "ApplicationPath:"${APP_PATH}
echo "ApplicationName:"${APP_NAME}
echo "Shutdown Application"
sh ${APP_PATH}/shutdown.sh
echo "Remove Application Package"
rm -rf ${APP_NAME}.bak
mv ${APP_PATH}/${APP_NAME} ${APP_PATH}/${APP_NAME}.${datenow}.bak
echo "Move Application jar to TargetPath"
mv /tmp/${APP_NAME} ${APP_PATH}
sh ${APP_PATH}/start.sh
start.sh 脚本内容
#!/bin/sh
APP_PATH=$(cd `dirname $0`; pwd)
APP_NAME=invoice.war
echo "Start Application ${APP_NAME}"
cd ${APP_PATH}/
setsid java -jar -Dspring.profiles.active=mer ${APP_NAME} > nohup.out 2>&1 &
echo $!
echo Start Success!
以上是 SpringBoot项目启动脚本 的全部内容, 来源链接: utcz.com/z/518544.html