Home > Java > javaTutorial > body text

How to start or stop the SpringBoot project in Centos

WBOY
Release: 2023-05-17 20:55:25
forward
1056 people have browsed it

使用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>
Copy after login

启动项目脚本

以项目名为rongyuan-project为例需先执行停止项目脚本

#!/bin/sh
sh bin/stop.sh
git pull
nohup mvn spring-boot:run -Drun.profiles=prod &
tailf nohup.out
Copy after login

项目停止脚本

以项目名为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
Copy after login

tips:在项目中mkdir bin文件夹,然后在bin目录下touch start.sh与stop.sh,即可在项目中执行脚本,并且目录结构也更加优美.

The above is the detailed content of How to start or stop the SpringBoot project in Centos. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template