springboot项目后台启动,附送一键启动脚本

nohup java -jar xxxxxx.jar > catalina.out 2>&1 &

参数解释:

nohup        意思就是不挂断运行,没此参数挂断连接会停止程序

>contro_log.out   :意思就是将标准输出重定向到了 ./contro_log.out

2>&1        :意思就是将标准错误重定向到标准输出。这里标准输出已经重定向到了 ./contro_log.out ,那么标准错误也会输出到./contro_log.out

&          :后台运行

附上启动脚本代码:

#!/bin/sh
RESOURCE_NAME=xxxx-1.0-SNAPSHOT.jar
RESOURCE_LOCATION=/home/myapp

bootApp

stop(){
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo '-->Stopping 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 '-->Killing Process!'
    kill -9 $tpid
else
    echo '-->Stop application successful!'
fi
rm -f tpid
}
start(){
echo 'Starting application ['$RESOURCE_NAME']...'
nohup java -Xms256m -Xmx2048m -XX:PermSize=32m -XX:MaxPermSize=256m -jar $RESOURCE_LOCATION/$RESOURCE_NAME > catalina.out 2>&1 &
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ];then
    echo '-->PID['${tpid}'],App started success...'
else
    echo '-->App started failed...'
fi
rm -f tpid
}

bootApp(){
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'App was started'
    stop
    start
else
    echo 'App was Stopped'
    start
fi
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值