如何确保在systemd中启动服务之前存在延迟? [英] How to ensure that there is a delay before a service is started in systemd?

查看:164
本文介绍了如何确保在systemd中启动服务之前存在延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务依赖于 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆