首页 > 解决方案 > spring boot 应用程序启动后如何将 systemd 服务状态设置为“activ”?

问题描述

我将 Spring Boot 服务设置为相互依赖的 systemd 服务。为此,我设置了 fe Requiers=config-service。所以启动顺序是正确的,问题是,当相应的spring boot应用程序启动时,systemd服务将其状态设置为“activ”。这意味着下一个 systemd 服务在 spring boot 应用程序完成之前启动。这会导致 spring boot 服务启动失败,这取决于之前的服务。

我尝试设置一个 ExecStartPre=/bin/sleep 30。但是这个数字是位 rondom 并且系统运行的硬件不同。所以有一个风险,即使这 30 多岁也不够,而且感觉……不干净

第一个 Spring Boot 服务是一个配置服务。它的系统服务是

[Unit]
Description=Config service
After=syslog.target network.target

[Service]
User=pi
ExecStart=/var/mapps/config-service.jar SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

它的下一个依赖服务是

[Unit]
Description=Discovery service
After=syslog.target network.target config-service.service
Requires=config-service.service

[Service]
User=pi
ExecStart=/var/myapps/discovery-service.jar SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

为了使 Spring Boot Apps 可作为 systemd 服务启动,我添加了

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
      <executable>true</executable>
  </configuration>
</plugin>

在我的 pom.xml

我预计,在 Spring Boot 服务启动后 systemd 服务会进入“活动”状态,但是当 Spring Boot 服务开始启动时,systemd 服务是“活动”的。

标签: javalinuxmavenspring-bootsystemd

解决方案


推荐阅读