springBoot优雅停服务配置

1、 在微服务pom.xml文件中,配置spring-boot-starter-actuator 监控组件

 <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
 </dependency>

2、application.yml 配置文件中加入:

#优雅停服务配置
management:
  endpoint:
    shutdown:
      enabled: true  #启用shutdown
  endpoints:
    web:
      exposure:
        include: "*"
      base-path: /actuator #自定义管理端点的前缀(保证安全)
  server:
    port: ${server.port}
    address: 127.0.0.1 #不允许远程管理连接(不允许外部调用保证安全)

3、shell脚本:

shutdown.sh`

#!/bin/sh
echo "stopping application...."
curl -X POST 127.0.0.1:xxxx/actuator/shutdown
tail -f nohup.out

start.sh

#!/bin/bash
echo "running...."
cd /xxx/xxx/
nohup java -jar xxxxxx.jar >/xxx/xxx/nohup.out &
echo "running finish"
tail -f nohup.out
原文地址:https://www.cnblogs.com/kt-ting/p/13984223.html