Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a user service in ~/.config/systemd/user/example.service like so:

Description=Example service

ExecStart=/bin/bash -c 'host > /var/tmp/example'


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/ 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 How do I make it wait for before running?

share|improve this question
up vote 1 down vote accepted

Forget the man systemd.special says:
       systemd automatically adds dependencies of type After for
       this target unit to all SysV init script service units
       with an LSB header referring to the $network facility.

So, this target is primarily a compatibility hack for SysV init scripts.

Assuming that your network connection is handled by NetworkManager you were of course right to depend on this target because NetworkManager.service defines But this only means that NetworkManager has been started, not that the network connection is actually established. That may take a while (dhcp roundtrips, wifi handshake, etc.) and is entirely the business of NetworkManager. At least on my system (F18) there is a service called NetworkManager-wait-online. It uses the nm-online utility program to block until there is an active connection established. Try to Require, Before that in your Unit definition or use that tool on its own.

share|improve this answer
I'm using dhcpcd (NetworkManager is way overkill for a server, in my opinion), but either way I haven't found a way to depend on a forking executable in a service definition... – dflemstr Feb 3 '13 at 10:32

I was having the same problem, with a userland backup script that needs access to the internet. I solved it by adding ~/.config/systemd/user/wait-for-network.service that just pings until it is reachable:

Description=Ping a server on the internet until it becomes reachable

ExecStart=/bin/bash -c 'while ! ping -c1; do sleep 1; done'

Then I made my backup script depend on it like this:


This works regardless of whether you use NetworkManager or some other means to establish the connection.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.