Linux服务器shell脚本自动化发布Spring boot项目

1 : 新建代码目录
系统目录
cd /auto/java
创建代码存放目录
mkdir code
创建发布包目录
mkdir package
创建发布包配置目录
mkdir config
2 : 拉取SVN代码

svn搭建参考链接:https://blog.csdn.net/qq_38254635/article/details/115697947
svn checkout SVN地址 --username=SVN账号 --password=SVN密码 服务器地址
eg:svn checkout svn://localhost/auto/code --username=admin --password=admin /auto/java/code

3 : 服务器搭建JDK

jdk搭建参考链接:https://blog.csdn.net/qq_38254635/article/details/115710067

4 : 服务器搭建maven

maven搭建参考链接:https://blog.csdn.net/qq_38254635/article/details/115708824

5 : 编写shell脚本文件

创建shell脚本文件,jar包日志文件

cd /auto/java
mkdir auto.sh
mkdir log.out

编辑shell脚本文件

vi auto.sh

shell脚本内容
jar包名称:business.jar
端口号:8080
配置文件:application.yml

echo "update and package svn code"
cd /auto/java/code
svn up
mvn clean
mvn package -DskipTests
echo "wait three second"
sleep 3
echo "move package, wait five second"
cd /auto/java/package
rm -rf business.jar
cp /auto/java/code/business/target/business-0.0.1-SNAPSHOT.jar /auto/java/package/business.jar
sleep 5
echo "kill process"
id=$(netstat -anp|grep 8080|awk '{printf $7}'|cut -d/ -f1)
if [ -n "$id" ];then
	echo "The current program process ID is $id, ready to close and restart."
	kill -9 $id
	sleep 3
else
	echo "The program did not start, restart started..."
fi
echo "clear log"
>/auto/java/log.out
echo "startup project"
nohup java -jar /auto/java/package/business.jar --spring.config.location=/auto/java/config/application.yml >/auto/java/log.out 2>&1 &
echo "view live log"
tail -f /auto/java/log.out

注:当jar包太大的时候,需要增加sleep 5,等待jar复制

你可能感兴趣的:(工作总结,linux,java,svn,shell,jar)