springboot之jar运行脚本

  一、现在的工程都将就独立和简单了,我们在使用springboot做开发或者其他框架做开发时,在linux上面执行的时候。总会写一下脚本,目的当然是为了更加好的运行程序。不然每次都手动输入一下命令,来调试环境。调整端口等。个人感觉特别麻烦,那么问题来了。为了更好的让项目运行并且看到其中的状态,所以一个好的脚本是非常重要的。

  二、这里个人记录一下自己常使用的jar启动脚本

  

#! /bin/sh
projectName="test"

#提醒功能
help() {
    echo "help: sh ${projectName}.sh [start|stop|restart]"
    exit 1
}

#判断项目是否运行,并且返回对应数字(0 为未启动 1为启动)
is_exist(){
    #获取pid的方式,个人喜欢咋写就咋写
    pid=`ps -ef|grep ${projectName}.jar|grep -v grep|awk '{print $2}'`
    if [ -z "${pid}" ]
    then
        return 0
    else
        return 1
    fi
}

#开始运行项目
start(){
    is_exist
    #如果正在运行直接提示
    if [ $? -eq 1 ]
    then
        echo "${projectName} is running"
        exit 0;
    else
        #没有运行则运行项目
        echo "start running ${projectName} ..."
        currentPath=`pwd`
        startPath=$(cd `dirname $0`;pwd)
        #这里写的比较简单,实际生产环境,需要配置参数
        cd ${startPath}
        nohup java -jar -server ${projectName}.jar > ${projectName}/run.log 2>&1 &
        cd ${currentPath}
    fi
}

#停止项目
stop(){
    echo "stop $projectName ..."
    is_exist
    if [ $? -eq 1 ]
    then
        #通过pid关闭
        kill -9 $pid
        echo  "[ok]"
    else
        echo  "[ok]"
    fi
}

//选择运行方式
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
*)
    help
    ;;
esac

  说明:if中的[]必须加空格

转载于:https://www.cnblogs.com/ll409546297/p/10536917.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值