-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dhcpcd service: order before network target #44524
Conversation
This reverts a change applied in PR NixOS#18491. When interfaces are configured by DHCP (typical in a cloud environment), ordering after network.target cause trouble to applications expecting some network to be present on boot (for example, cloud-init is quite brittle when network hasn't been configured for `cloud-init.service`) and on shutdown (for example, collectd needs to flush metrics on shutdown). When ordering after network.target, we ensure applications relying on network.target won't have any network reachability on boot and potentially on shutdown. Therefore, I think ordering before network.target is better.
The semantics of the |
ping @fpletz who had been working on dhcpcd and |
@Mic92 The dhcpcd unit already activates Dhcpcd can be configured to either wait for IPv4 or IPv6 but this will break IPv4-only or IPv6-only systems. Not sure what we should do here without introducing new options and rethinking the NixOS networking autoconfiguration logic. For instance, we might move away from automatic DHCP on all interfaces and let @vincentbernat The preferred solution for now is to add a |
It would solve half the problem. The documentation states if you use Moreover, I still think a system should do its best to ensure network is available when network.target is reached. The documentation may say this means nothing on boot, but many daemons use this ordering to get network in the easy cases (for servers where configuration can be done early in boot). For example, nginx is after network.target. If it listens on 0.0.0.0, no problem. If it listens on a specific IP address, it will crash (but hopefully be restarted, so it's not the perfect example). The fact that on other distributions (Debian, Redhat), DHCP is run before network.target for interfaces configured statically (in Also, I don't understand why static IP configuration is before network.target while dhcpcd is after network.target (well, I understand that DHCP may block boot, but on servers, DHCP is usually configured on purpose). |
Mhm. Redhat does this. Archlinux puts dhcpcd after network. Ubuntu does not apply any network target to dhcpcd. Ubuntu's networking target is bound to |
On Redhat and Ubuntu, the default DHCP client is ISC DHCP client, so maybe nobody cares about the ordering sequence during boot for dhcpcd. For Redhat, the service handling the network setup (both static IP and DHCP) is network.service and is run before network.target. In Ubuntu (Xenial, didn't check for Bionic which is using systemd-networkd), the networking.service is also before network.target and also handle both static IP and DHCP. On Debian, this is the same. In the three cases, for a server relying on these systems, unless there is some network issues, you can expect the network to be correctly configured after network.target. What was the problem when dhcpcd.service was before network.target? Just the ability to get a clean shutdown should favor going back to the initial situation. |
I've checked all mentioned distributions here and indeed all of their configured static and dynamic networking setup is ordered before If network-manager is used, the corresponding online-wait service is wanted by So in my opinion these distributions are only using this "hack" because they haven't implemented a proper wait-for-online service for their networking setup scripts and have to solve shutdown, too. If upstream or packages from those distros are distributing unit files using Back to the topic of this PR: You clearly have a point here. We should fix the shutdown problem and your PR fixes this like in other distros because we currently have no way to wait for dhcpcd out of band. I think we should merge this PR and continue to ensure we only use |
So regarding |
Some modules of cloud-init can cope with a network not immediately available (notably, the EC2 module), but some others won't retry if network is not available (notably, the Cloudstack module). network.target doesn't give much guarantee about the network availability. Applications not able to start without a fully configured network should be ordered after network-online.target. Also see NixOS#44573 and NixOS#44524.
Some modules of cloud-init can cope with a network not immediately available (notably, the EC2 module), but some others won't retry if network is not available (notably, the Cloudstack module). network.target doesn't give much guarantee about the network availability. Applications not able to start without a fully configured network should be ordered after network-online.target. Also see #44573 and #44524.
This change seems to delay lightdm startup by about 10 seconds on my system, making time-to-usable desktop much worse. I'm not sure why — systemd-analyze reports display-manager as running after 3 seconds, but it doesn't actually display the greeter until dhcpcd has completed. This patch makes it start up much more rapidly: a/nixos/modules/services/networking/dhcpcd.nix b/nixos/modules/services/networking/dhcpcd.nix
index efdbca5d52e..86c5adc8c2b 100644
--- a/nixos/modules/services/networking/dhcpcd.nix
+++ b/nixos/modules/services/networking/dhcpcd.nix
@@ -162,7 +162,7 @@ in
wantedBy = [ "multi-user.target" ] ++ optional (!hasDefaultGatewaySet) "network-online.target";
wants = [ "network.target" "systemd-udev-settle.service" ];
- before = [ "network.target" ];
+ before = optional (!hasDefaultGatewaySet) "network-online.target";
after = [ "systemd-udev-settle.service" ];
# Stopping dhcpcd during a reconfiguration is undesirable
|
I've tested this with a number of display managers — gdm and sddm are the same as lightdm wrt being delayed by dhcpcd; slim starts up fast both with and without this change. |
This problem sounds similar to |
This also affects nixos tests, adding 10s to each test run (!!) |
FWIW arch linux does order I don't think |
This little change gave me a lot of headaches since upgrading to NixOS 18.09. It increased the boot time to a usable desktop by 10s effectively doubling my laptop boot time. But the biggest headaches came from the fact that with no internet connection present the boot time is increased by 30+ seconds and all sorts of services malfunction or fail to start such as |
Motivation for this change
This reverts a change applied in PR #18491. When interfaces are
configured by DHCP (typical in a cloud environment), ordering after
network.target cause trouble to applications expecting some network to
be present on boot (for example, cloud-init is quite brittle when
network hasn't been configured for
cloud-init.service
) and onshutdown (for example, collectd needs to flush metrics on shutdown).
When ordering after network.target, we ensure applications relying on
network.target won't have any network reachability on boot and
potentially on shutdown.
Therefore, I think ordering before network.target is better.
cc @groxxda @fpletz
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)