使用Maven脚本在Centos服务器中启动与停止项目
首先项目需要引用Maven的SpringBoot插件
<profiles>
<profile>
<id>boot-repackage</id>
<build>
<plugins>
<plugin>
<groupId>org.spring work.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 & 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,即可在项目中执行脚本,并且目录结构也更加优美.
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
-
二层、三层、四层交换机的区别!!
2026-05-19栏目: 教程
-
阿里云安全肖力:云原生安全定义下一代安全架构
2026-05-19栏目: 教程
-
阿里巴巴开源 Sentinel 限流方案搭建
2026-05-19栏目: 教程
-
微信开发之token认证
2026-05-19栏目: 教程
-
白皮书首发:173位大数据决策者眼中的数据中台是长这样的
2026-05-19栏目: 教程
