Linux运行Springboot项目,因为不是正式部署,开发中需不断地调试,修改,更新,重启。每次都需要经过多步,所以考虑shell自动运行。
#!/bin/bash
name=$(lsof -i:10001|tail -1|awk '"$1"!=""{print $2}')
if [ -z $name ]
then
echo "No process can be used to killed!"
else
id=$(lsof -i:10001|tail -1|awk '"$1"!=""{print $2}')
kill -9 $id
echo "Process name=$name($id) kill!"
fi
cd /root/apps/project_name
echo 'cd /root/apps/project_name'
git pull
nohup mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Duser.timezone=GMT+8" >output 2>&1 &
echo 'start sucess!'
exit 0
说明:
10001为程序运行端口,根据lsof -i:port查找已运行的程序,如果存在则kill该进程。
进入程序目录:cd /root/apps/project_name
执行 git pull (参考之前发表的博客,git免密码拉取代码)
运行 mvn spring-boot:run 具体参数可自行修改,也可以逐步打包,运行java -jar xx.jar等
进入服务器,创建脚本 vi start.sh,编写之后保存脚本。
授权可执行:chmod u+x start.sh
运行即可:./start.sh

本文介绍了一种在Linux环境下简化SpringBoot项目调试流程的方法。通过编写shell脚本实现自动停止旧进程、更新代码并重新启动SpringBoot应用,极大地提高了开发效率。
2934

被折叠的 条评论
为什么被折叠?



