Is there any way to configure a systemd service (e.g. serviceX) to wait for the connmand service to finish configuring network interfaces prior to serviceX running ? From what I understand of systemd, using or relying on the network.target is pointless because that functionality is horribly broken. The system I'm using (BeagleBone Black with Angstrom Linux) uses connman rather than NetworkManager.
Wait for connman to finish configuring the network in a sytemd system
3.4k views Asked by Alex Marshall AtThere are 3 answers
Following the instructions here, I found that this line (in the [Unit] section of the .service file) worked for me:
Wants=network-online.target #wait for network up. Can slow down script.
I applied this fix for the purpose described, to get opkg upgrade
working correctly, which it now does. I think using network-online
rather than network
may be the trick.
According to systemd documentation, all systemd units that need to wait for a working online connection at boot time need to include the following:
[Unit]
...
Wants=network-online.target
After=network-online.target
If you want to be compatible with older systemd versions, you can also use:
[Unit]
...
Wants=network.target network-online.target
After=network.target network-online.target
That's for systemd. With NetworkManager (for completeness, I'm aware you're not using it), this works since the upstream versions 0.9.10 and some distributions including Fedora also worked with older upstream versions.
https://bugzilla.gnome.org/show_bug.cgi?id=728965
As you are using connman instead, you need to check whether connman implements network-online.target
correctly. Checking connman 1.30 source code reveals no appearance of network-online.target
at all, so I must assume that connman is lagging behind. You may want to start a feature request in connman and/or your linux distribution. In that case it would be nice if you added a note about it here.
Basically, with newer systemd versions, a network service that implements network-online.target correctly, and services using the correct dependencies, everything should work out of the box for the user.
According to a comment to the other answer, the Unit section of connman.service
looks as follows:
[Unit]
Description=Connection service
After=syslog.target
There should really be at Before=network.target
, at the least. The After=syslog.target
is redundant with current systemd versions. But full implementation of network-online.target
would be preferred.
Wants=network.target network-online.target
andAfter=network.target network-online.target
seem to be insufficient for Angstrom on the BeagleBone Black at the time of this writing. I also had to addconnman.service
toWants=
in order to get everything to work correctly.