如何确保在systemd中启动服务之前存在延迟?

编程入门 行业动态 更新时间:2024-10-25 22:31:57
本文介绍了如何确保在systemd中启动服务之前存在延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我的服务依赖于 Cassandra 正常启动以及集群启动和准备就绪.

I am having a service that depends on Cassandra coming up gracefully and the cluster being up and ready.

为了确保满足依赖顺序,我有以下单元文件

To ensure that the dependency order is met, I have the following unit file

[Unit]
Requires=cassandra.service
After=cassandra.service

[Service]
Environment=JAVA_HOME=/usr/java/jre
ExecStart=@bringup.instance.path@/webapps/bringup-app/bin/bringup
TimeoutStartSec=0
ExecStop=
PIDFile=@bringup.instance.path@/logs/bringup.pid
Restart=always

[Install]
WantedBy=multi-user.target

我如何确保启动应用进程在尝试启动之前等待 30 秒?目前,尽管它是在 Cassandra 之后启动的,但我注意到 Cassandra 集群尚未启动,因此作为启动的一部分,来自启动应用程序连接到 Cassandra 的任何尝试都失败了.

How do I ensure that the bringup-app process waits for 30 seconds before it attempts to start up? Currently although it is started after Cassandra, I have noticed that the Cassandra cluster is not up yet and hence any attempt from the bringup-app to connect to Cassandra as part of startup fails.

因此我想添加一个延迟.可以通过单元文件实现吗?

I therefore want to add a delay. Is that possible via the unit file?

推荐答案

您可以运行 ExecStart<之前执行noreferrer">睡眠 命令/a> 与 ExecStartPre :

You can run the sleep command before your ExecStart with ExecStartPre :

[Service]
ExecStartPre=/bin/sleep 30

这篇关于如何确保在systemd中启动服务之前存在延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 12:10:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:systemd

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!