SpringBoot project generation and deployment

SpringBoot project generation and deployment

1. Project generation

https://start.spring.io/

2. Start the project

How to start the jar package

illustrate

java -jar xxx.jar

The ctrl+c process will also be automatically closed, and silent operation can be added at the end &

nohup java -jar xxx.jar --spring.profiles.active=test > /dev/null 2>&1 &

Optional parameter --spring.profiles.active=test sets environment variables

nohup java -jar xxx.jar 2>&1 &

Record screen output to log file

nohup java -jar xxx.jar >myout.log 2>&1 &

nohup java -jar springboot.jar --server.port=8181 >outlog.log 2>&1 &

output the log to another file

nohup java -Dserver.port=8086 -Dspring.config.additional-location=./application-dev.yml -jar ./springboot.jar> nohup.out 2>&1 &

Load the server configuration file application-dev.yml

3. Startup and shutdown scripts

1) start

#!/bin/sh

#

# 启动 jar 运行

# 项目部署目录

projectDir=/opt/springboot/

# 项目运行 jar 名称

jarName="springbootdemo.jar"

# 脚本日志目录

logDir=/var/log/springbootdemo/

# 项目部署环境

profileActive=dev

# 这里的-x 参数判断${logDir}是否存在并且是否具有可执行权限

if [ ! -x "${logDir}" ]; then

mkdir -p "${logDir}"

fi

# 判断项目SpringBoot程序是否运行

count=$(ps -ef |grep ${jarName} |grep -v "grep" |wc -l)

if [ ${count} -lt 1 ]; then

cd ${projectDir}

nohup java -jar ${jarName} --spring.profiles.active=${profileActive} > /dev/null 2>&1 &

echo "$(date '+%Y-%m-%d %H:%M:%S') 启动 ${jarName} 程序 ... ..." >> ${logDir}$(date "+%Y-%m-%d").log

else

echo "$(date '+%Y-%m-%d %H:%M:%S') ${jarName} 程序运行正常 !!! !!!" >> ${logDir}$(date "+%Y-%m-%d").log

fi

2) off

#!/bin/sh

#

# 停止 jar 运行

# 项目部署目录

projectDir="/opt/springboot/"

# 项目运行 jar 名称

jarName="springbootdemo.jar"

# 脚本名称

scriptName="stop-springboot.sh"

# 判断项目SpringBoot程序是否运行

count=$(ps -ef |grep ${jarName} |grep -v "grep" |wc -l)

if [ ${count} -gt 0 ]; then

echo "已经存在 ${count} 个${jarName} 程序在运行"

# 获取正在运行的程序进程 id(排除 grep 本身、awk 命令以及脚本本身)

jarPid=$(ps x | grep ${jarName} | grep -v grep | grep -v '${scriptName}' | awk '{print $1}')

# 停止正在运行的项目进程

kill -9 ${jarPid}

output=`echo "正在关闭${jarName}程序,进程id: ${jarPid}"`

echo ${output}

else

echo '没有对应的程序在运行'

fi

# 删除 jar 包

rm -rf ${projectDir}${jarName}

# 进入 项目部署目录

cd ${projectDir}

Guess you like

Origin blog.csdn.net/kanhcj86/article/details/130755279