I have a user service in ~/.config/systemd/user/example.service
like so:
[Unit]
Description=Example service
After=network.target
[Service]
ExecStart=/bin/bash -c 'host google.com > /var/tmp/example'
[Install]
WantedBy=default.target
The actual service I'm trying to control actually does something useful and accesses the network, of course; this is just a simplified example.
The service is enabled via systemctl --user enable example.service
which creates the symlink ~/.config/systemd/user/default.target.wants/example.service
pointing to ~/.config/systemd/user/example.service
.
With this setup, and with systemd
user sessions enabled as described on the Arch Wiki, the service is started as my user upon startup. However, it is not actually started after the network is set up; instead, it seems to start immediately, since /var/tmp/example
contains:
;; connection timed out; no servers could be reached
(And the actual service that I'm trying to control can't reach the network either, and fails with similar name-lookup errors)
This means that the service doesn't actually run after network.target
. How do I make it wait for network.target
before running?