简体   繁体   English

systemd启动服务后另一个停止问题

[英]systemd start service after another one stopped issue

I have 2 services that i need to start. 我需要启动2项服务。 First service has download jobs required for second service. 第一个服务具有第二个服务所需的下载作业。

First service 第一次服务

[Unit]
Description=First
After=network.target

Second service 第二次服务

[Unit]
Description=Second
After=First

Problem is they both start at the same time, i need second service to wait until first one is dead. 问题是它们都是在同一时间开始,我需要第二次服务才能等到第一个服务失效。 I don't wait to use sleep because download jobs can be big. 我不等待使用睡眠,因为下载工作可能很大。 Thank you. 谢谢。

In your first service add 在您的第一个服务添加

ExecStopPost = /bin/systemctl start Second

what this does is when the service terminates the above option is activated and thus second service is called. 这样做是当服务终止时,激活上述选项,从而调用第二个服务。

This particular option(ExecStopPost) allows you to execute commands that are executed after the service is stopped. 此特定选项(ExecStopPost)允许您执行在服务停止后执行的命令。 This includes cases where the commands configured in ExecStop= were used, where the service does not have any ExecStop= defined, or where the service exited unexpectedly. 这包括使用ExecStop中配置的命令的情况,其中服务没有定义任何ExecStop =,或服务意外退出的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM