Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A Systemd unit needs to start at boot but wait for network

Yup that's the recommended way to do it. Wants adds the network-online.target as a soft dependency.[1] Systemd will try to start it if it isn't up already. Networking should work after this target...

posted 7mo ago by Iizuki‭  ·  edited 7mo ago by Iizuki‭

Answer
#2: Post edited by user avatar Iizuki‭ · 2024-04-22T07:38:04Z (7 months ago)
Wording
  • Yup that's the recommended way to do it.
  • [`Wants`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Wants=) adds the [`network-online.target`](https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#network-online.target) as *a soft* dependency.[^hard-dependency] Systemd will try to start it if it isn't up already. Networking should be up after this target.
  • [`After`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Before=) specifies the ordering related to other units. Without this they would likely be started concurrently.
  • You almost always want the two directives. One for the dependency and one for their ordering. Here's an exception though:
  • DNS lookups work after [`nss-lookup.target`](https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#nss-lookup.target) so you probably don't want your unit to be scheduled before this. The docs tell us not to add it to `Wants`. This way systemd won't start it when your unit is started, but should they happen to be in the same transaction – say, during the boot – then the ordering is respected.
  • [^hard-dependency]: You could consider a hard dependency with [`Requires`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Requires=), but soft dependencies are recommended for a more robust boot.
  • Yup that's the recommended way to do it.
  • [`Wants`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Wants=) adds the [`network-online.target`](https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#network-online.target) as *a soft* dependency.[^hard-dependency] Systemd will try to start it if it isn't up already. Networking should work after this target.
  • [`After`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Before=) specifies the ordering related to other units. Without this they would likely be started concurrently.
  • You almost always want the two directives. One for the dependency and one for their ordering. Here's an exception though:
  • DNS lookups work after [`nss-lookup.target`](https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#nss-lookup.target) so you probably don't want your unit to be scheduled before this. The docs tell us not to add it to `Wants`. This way systemd won't start it when your unit is started, but should they happen to be in the same transaction – say, during the boot – then the ordering is respected.
  • [^hard-dependency]: You could consider a hard dependency with [`Requires`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Requires=), but soft dependencies are recommended for a more robust boot.
#1: Initial revision by user avatar Iizuki‭ · 2024-04-19T07:28:29Z (7 months ago)
Yup that's the recommended way to do it.

[`Wants`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Wants=) adds the [`network-online.target`](https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#network-online.target) as *a soft* dependency.[^hard-dependency] Systemd will try to start it if it isn't up already. Networking should be up after this target.

[`After`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Before=) specifies the ordering related to other units. Without this they would likely be started concurrently.

You almost always want the two directives. One for the dependency and one for their ordering. Here's an exception though:

DNS lookups work after [`nss-lookup.target`](https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#nss-lookup.target) so you probably don't want your unit to be scheduled before this. The docs tell us not to add it to `Wants`. This way systemd won't start it when your unit is started, but should they happen to be in the same transaction – say, during the boot – then the ordering is respected.


[^hard-dependency]: You could consider a hard dependency with [`Requires`](https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Requires=), but soft dependencies are recommended for a more robust boot.