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:
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
sudo systemctl enable systemd-networkd-wait-online.service.
Now I have in
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 --userruns as a separate process from the
systemd --systemprocess. 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
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: Reached target Network. Jul 18 19:20:11 calc-server systemd: 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: Reached target Network is Online. Jul 19 00:35:38 calc-server systemd: Starting Network is Online.