在開發(fā)springboot的項目,經(jīng)常需要部署到服務(wù)器上哲思,之前的操作是:打jar包惯殊,鏈接服務(wù)器,上傳jar包也殖,執(zhí)行shell土思。
一套流程下來,至少大概需要十分鐘忆嗜,借鑒了renren開源的部署腳本己儒,直接用maven插件部署,如下:
maven配置
<build>
<finalName>openbbs</finalName>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.8</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<fromFile>target/openbbs.jar</fromFile>
<url>scp://oss:oss@10.5.189.230/home/oss/openbbs/</url>
<commands>
<!-- Kill Old Process -->
<command>bash /home/oss/openbbs/restart.sh</command>
</commands>
<!-- 運行命令 mvn clean package wagon:upload-single wagon:sshexec-->
<!-- 運行命令 mvn package wagon:upload-single wagon:sshexec-->
<displayCommandOutputs>true</displayCommandOutputs>
</configuration>
</plugin>
</plugins>
</build>
服務(wù)器上shell腳本:
#!/bin/bash
gmpid=$(ps -ef | grep openbbs.jar | grep -v grep | awk '{print $2}')
if [[ "$gmpid" != "" ]] ;then
kill -9 $gmpid && echo "openbbs.jar stopd "
fi
nohup /usr/java/jdk1.8.0_121/bin/java -jar /home/oss/openbbs/openbbs.jar > /home/oss/openbbs/renren.log 2>&1 &
ps -ef | grep openbbs | grep -v grep