java - 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 服务是“活动”的。
解决方案
推荐阅读
- android - 将圆圈放在图标后面并选择颜色
- c++ - FIFO 块程序,直到其他进程读取
- gtk - 处理“将孩子添加到 Gtk.Box”事件
- python - 无法通过 PIP 安装任何新软件包 | 蟒蛇
- java - JSTL fn:subStringBetween?
- java - 为什么我的 Spring Boot 错误控制器不起作用?
- vue.js - 使用 vue-cli3 删除插件
- java - 当服务器响应需要很长时间时如何使客户端不断开连接
- python - 如何将通过输入命令输入的值存储在列表中
- java - Robot.getPixelColor 与 BufferedImage.getRGB