使用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 &
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,即可在項目中執行腳本,並且目錄結構也更加優美.