SpringBoot项目部署到服务器后台运行

mac2024-07-13  50

其中的jar包改成你自己的

一、编写脚本文件

1、启动脚本

start.sh

nohup java -jar mydepartment-0.0.1-SNAPSHOT.jar & echo Start Success!

2、停止脚本

stop.sh

#!/bin/bash PID=$(ps -ef | grep mydepartment-0.0.1-SNAPSHOT.jar | grep -v grep | awk '{ print $2 }') if [ -z "$PID" ] then echo Application is already stopped else echo kill $PID kill $PID fi

3、重启脚本

restart.sh

#!/bin/bash echo stop application source ./stop.sh echo start application source ./start.sh

4、检查脚本

check.sh

#!/bin/sh APP_NAME=mydepartment-0.0.1-SNAPSHOT tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'App is running.' else echo 'App is NOT running.' fi

二、赋予权限

chmod +x start.sh chmod +x stop.sh chmod +x restart.sh chmod +x check.sh

三、运行脚本

./start.sh # 查看运行状态 netstat -ntpl|grep java

也可以选择使用Docker

Docker部署Spring Boot项目

欢迎评论交流!!!

最新回复(0)