I have written a couple of systemd user service files which I want users to enable and which need a working network connection. I thought that would be as easy as:
Wants=network-online.target
After=network-online.target
However, the services seem to start too early, and in journalctl
I see:
network-online.target: Cannot add dependency job, ignoring: Unit network-online.target failed to load: No such file or directory.
Then I searched more and tried
Wants=network.target
After=network.target
and did sudo systemctl enable systemd-networkd-wait-online.service
.
Now I have in journalctl
:
network.target: Cannot add dependency job, ignoring: Unit network.target failed to load: No such file or directory.
And again the service starts too early.
Is that message supposed to be there? How can I debug my problem?
EDIT: the reason is simple and specifically stated in the Arch Wiki:
systemd --user
runs as a separate process from thesystemd --system
process. User units can not reference or depend on system units.
This forum post seems to suggest a simple solution: I should link
the necessary system unit as a user, thus creating a symlink to it available on the unit search path.
After doing that, I don't see any No such file or directory
messages, however, I still can't make the services actually run after the network is online.
I have tried linking network.target
, network-online.target
and systemd-networkd-wait-online.service
, setting my units to depend on each of them, with no success. When I check the linked unit's status in user mode, they are all some of them are dead, e.g.:
$ systemctl --user status network.target
● network.target - Network
Loaded: loaded (/usr/lib/systemd/system/network.target; linked; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd.special(7)
http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
$ systemctl status network.target
● network.target - Network
Loaded: loaded (/usr/lib/systemd/system/network.target; static; vendor preset: disabled)
Active: active since Sat 2015-07-18 19:20:11 MSK; 3h 35min ago
Docs: man:systemd.special(7)
http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
Jul 18 19:20:11 calc-server systemd[1]: Reached target Network.
Jul 18 19:20:11 calc-server systemd[1]: Starting Network.
However, I can see network-online.target
active in user mode after linking it:
$ systemctl --user status network-online.target
● network-online.target - Network is Online
Loaded: loaded (/usr/lib/systemd/system/network-online.target; linked; vendor preset: enabled)
Active: active since Sun 2015-07-19 00:35:38 MSK; 2min 48s ago
Docs: man:systemd.special(7)
http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
Jul 19 00:35:38 calc-server systemd[469]: Reached target Network is Online.
Jul 19 00:35:38 calc-server systemd[469]: Starting Network is Online.
link
the units? I triedsystemctl --user link /lib/systemd/system/network.target
and then withsystemctl --user status network.target
still gotLoaded: not-found (Reason: No such file or directory)
... – TCB13 Nov 22 '15 at 10:42network.target
is at/usr/lib/systemd/system/network.target
. – Lev Levitsky Nov 22 '15 at 10:59cat
I get the file on the path, however systemd can't read it, look at this: http://pastebin.com/RpsbP3qg – TCB13 Nov 22 '15 at 11:07systemctl --user
as root, I'm not sure how that should work. Running it as user works for me (creates a symlink). – Lev Levitsky Nov 22 '15 at 11:13systemctl --user link /usr/lib/systemd/system/network-online.target
– lsl Nov 14 '18 at 21:48