需求
- C服务需要在A服务和B服务都启动成功后才能启动
| 服务编号 | 服务名 |
|---|---|
| 服务A | nginx.service |
| 服务B | mashang.service |
| 服务C | redis.service |
实验
- 如果您想要 redis.service 在 nginx.service 和 mashang.service 都成功启动后才能启动,那么需要在 redis.service 的服务单元文件中使用 Wants= 或 Requires= 以及 After= 指令来定义这些依赖关系。
- 希望 redis.service 在两个其他服务都成功启动后才启动,应该使用
Requires=而不是Wants=,因为 Requires= 会确保所有列出的服务都被启动,并且如果其中任何一个服务启动失败,redis.service 也会被视为启动失败。
vim /etc/systemd/system/redis
文件内容如下:
[Unit]
Description=Redis data structure server
After=network.target nginx.service mashang.service
Requires=nginx.service m

最低0.47元/天 解锁文章
2822

被折叠的 条评论
为什么被折叠?



