SpringBoot项目启动脚本

原创
2020/07/21 11:41
阅读数 360

以自己创建的项目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!

可以添加限定jvm内存

export MALLOC_ARENA_MAX=4
JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8"
setsid java $JAVA_OPTS  -jar -Dspring.profiles.active=ppt ${APP_NAME} > nohup.out 2>&1 &

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部