Services (.service)

Order a service after the network or another unit (After, Requires, Wants)

4 min · updated June 15, 2026

Two separate questions trip people up: ordering (who starts first) and requirement (must the other unit be running at all). systemd uses different directives for each.

Ordering vs. requirement

[Unit]
Description=My API
# Ordering: start this AFTER postgresql is up:
After=postgresql.service
# Requirement: pull postgresql in, and fail/stop if it fails:
Requires=postgresql.service

Rule of thumb: pair an ordering directive (After=) with a requirement directive (Wants= or Requires=). They are independent.

Waiting for the network correctly

[Unit]
After=network-online.target
Wants=network-online.target
sudo systemctl enable systemd-networkd-wait-online.service   # systemd-networkd
# or, on NetworkManager:
sudo systemctl enable NetworkManager-wait-online.service

Apply

sudo systemctl daemon-reload
sudo systemctl restart myapi.service
# See what it actually waited for:
systemctl list-dependencies myapi.service

Gotchas: ordering directives reference the dependency’s start-up; on shutdown the order is reversed automatically. Don’t over-use Requires= — a single flaky dependency can block your whole service. For “start mine, and if it dies take the helper with it”, that’s BindsTo= + After=.

← All recipes