I'm trying to create a custom network management service for a CentOS 7
netboot image. The service gets a list of all interfaces on the host, finds one with a physical connection, and then uses it to pull the DHCP configuration.
The problem is making sure that it starts after all the network devices exist on the system, so it can get a list of them. Here's my unit file:
[Unit]
Description=Configure networking
Wants=network.target
After=network-pre.target
Before=network.target multi-user.target
[Service]
ExecStart=/usr/local/bin/netboot-cfg
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
As you can see, it runs after the network-pre
target, and before the network
target. I confirmed this with systemd-analyze plot
. However, it's unable to find any interfaces on the system at that point in the boot process. The list is created by looking at the /sys/class/net
directory. The sys-subsystem-net-devices-<iface>.device
units are started later, which I'm guessing populate that directory.
It seems strange to me that the network device units start after network.target
.
So the question is: How can I reliably determine when all the interfaces will be available, using systemd unit file syntax?
Best Answer
Parts of this question are answered by this Unix SE thread.
Basically, per the documentation for network.target:
network.target guarantees only that the network stack is up:
network-online.target
So you may want to adjust your requirements to reflect this: I think you might want to run your script
After=network.target
, butBefore=network-online.target
.