Skip to content

Lesson 3 of 9 · 24m

Dependencies and Ordering: The Graph Is the Truth

How Wants, Requires, After, Before, and unit activation interact — and how to express real prerequisites without creating boot deadlocks.

The most expensive systemd confusion is treating dependency and ordering as the same thing. They are separate axes. A unit can be required but unordered, ordered but optional, both, or neither.

Requirement versus ordering

[Unit]
Wants=network-online.target
After=network-online.target

Wants= says "if this unit starts, try to start that one too." It does not require success or define timing. After= says "start this unit only after that unit finishes activation" but creates no requirement. Most real dependencies need both: pull it in, then order against it.

The strict cousins matter:

  • Requires=: this unit fails if the required unit fails to activate.
  • BindsTo=: like Requires, plus this unit stops when the bound unit stops.
  • PartOf=: stop/restart operations propagate from the dependency.
  • Conflicts=: units cannot run together.

Use strict coupling only when the dependency is genuinely mandatory. Otherwise small failures turn into broad outages.

Ordering is not application health

After=postgresql.service means PostgreSQL finished activation, not that migrations are complete or your workload is accepted. With Type=notify, readiness can be meaningful. With Type=simple, it may mean only that a process exec'd.

Socket activation often removes the problem entirely:

# app.socket
[Socket]
ListenStream=127.0.0.1:8080

[Install]
WantedBy=sockets.target

systemd binds the socket early, then starts app.service when traffic arrives. Clients can connect while the service finishes initializing.

Transactions and deadlocks

systemctl start foo.service builds a transaction: every state change needed to satisfy the request. Circular ordering makes that transaction impossible, and the journal says so explicitly:

systemd[1]: ssh.service: Found ordering cycle on networking.service/start
systemd[1]: ssh.service: Job networking.service/start deleted to break ordering cycle

Do not add random Before= lines. Draw the graph, find the false edge, and remove or weaken it.

Conditions are gates, not waits

[Unit]
ConditionPathExists=/etc/acme/enabled

A failed condition skips the unit cleanly. It is not a way to wait for a file that appears later; conditions are evaluated when activation is attempted.

Field notes

  • network.target does not mean interfaces have addresses; use network-online.target only when configured networking is truly required.
  • Ordering everything after network-online.target can delay boot for seconds on intermittent links.
  • Inspect both sides with systemctl list-dependencies --after --before unit.
  • Boot deadlocks are graph bugs. Debug them as graph bugs, not with sleeps.

Was this lesson helpful?

Sign in to rate