Centos下SpringBoot项目启动与停止脚本

使用Maven脚本在Centos服务器中启动与停止项目

首先项目需要引用Maven的SpringBoot插件

    <profiles>
        <profile>
            <id>boot-repackage</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

启动项目脚本

 以项目名为rongyuan-project为例需先执行停止项目脚本
#!/bin/sh
sh bin/stop.sh
git pull
nohup mvn spring-boot:run -Drun.profiles=prod &
#springboot2.x以上版本的插件发布 
#为了规避指令冲突参数统一加上spring-boot前缀spring-boot.run.profiles=prod
#jar包发布脚本为 java -jar -Dspring.profiles.active=prod
tailf  nohup.out

项目停止脚本

以项目名为rongyuan-project为例
#!/bin/bash
PID=$(ps -ef | grep rongyuan-project | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
    echo rongyuan is already stopped
else
    echo kill $PID
    kill $PID
fi

tips:

  在项目中mkdir bin文件夹,然后在bin目录下touch start.sh与stop.sh,即可在项目中执行脚本,并且目录结构也更加优美.
    原文作者:独上兰舟
    原文地址: https://segmentfault.com/a/1190000017158690
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞