问题原文
原帖链接 · TomOnTime · CC BY-SA 3.0
I'm creating a systemd .service file and I need help understanding the difference between Requires= and After=. The man page says that Requires= "Configures requirement dependencies on other units." and After= "Configures ordering dependencies between units." What's the difference?
社区高分解答
原帖链接 · Sufiyan Ghori · CC BY-SA 4.0
One of the major difference is,
Afteronly checks if the unit is activated already, and does not explicitly activate the specified units.- The units listed in
Requiresare activated together with the unit. If any of the required units fail to start, the unit is not activated.
Consider I have a unit file test-app.service,
[Unit]
Description=test app
After=network-online.target
Here is what will happen when this statement is executed,
Afterchecks ifnetwork-online.target.- if
network-online.targetnot started, it will wait. test-appstarts only afternetwork-online.targetis active
If I had Requires instead,
[Unit]
Description=test app
Requires=network-online.target
Here is what will happen when this statement is executed,
network-online.targetandtest-appare activated together- if
network-online.targetfails to starttest-appwill not be activated.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
