diff options
author | Will Fancher <elvishjerricco@gmail.com> | 2023-06-06 22:41:08 -0400 |
---|---|---|
committer | Will Fancher <elvishjerricco@gmail.com> | 2023-06-08 00:25:15 -0400 |
commit | 5d6ea734a18203895360f6ea767ee47f7be22e00 (patch) | |
tree | 9da1bf7ad21b04ae60ab4e8b220c1503aa4196c0 /nixos | |
parent | a9e34ff905798ec1a727312de4137e48a7b8dd2f (diff) |
systemd stage 1 networking: Stop systemd-networkd on switch-root
This essentially backports
https://github.com/systemd/systemd/pull/27791. `systemd-networkd.service`
is sent the `SIGTERM` signal, but it is not required to be stopped
before `initrd-switch-root.target` is reached, despite the use of
`systemctl isolate initrd-switch-root.target`. This is because when
there is no ordering at all between two units, and a transaction stops
one and starts the other, the two operations can happen
simultaneously. This means the service could still be running when
`switch-root` actually occurs. Then, stage 2 systemd will see the
service still running and decide it doesn't need to add a start
operation for it to its initial transaction. Finally, the service
exits, but only after it's already too late. If, however, there is any
ordering at all between a stopping unit and a starting unit, then the
stop operation will be done first. This way, we ensure that the
service is properly exited before doing `switch-root`.
This is something to keep in mind going forward. There may be other
services that need this treatment. These `before` and `conflicts`
definitions are the correct way to ensure a unit is actually stopped
before you reach initrd-switch-root
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/system/boot/networkd.nix | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index 463e2b8d90b0..d88f88f9fdaf 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -3188,7 +3188,19 @@ let systemd.contents."/etc/systemd/networkd.conf" = renderConfig cfg.config; - systemd.services.systemd-networkd.wantedBy = [ "initrd.target" ]; + systemd.services.systemd-networkd = { + wantedBy = [ "initrd.target" ]; + # These before and conflicts lines can be removed when this PR makes it into a release: + # https://github.com/systemd/systemd/pull/27791 + before = ["initrd-switch-root.target"]; + conflicts = ["initrd-switch-root.target"]; + }; + systemd.sockets.systemd-networkd = { + wantedBy = [ "initrd.target" ]; + before = ["initrd-switch-root.target"]; + conflicts = ["initrd-switch-root.target"]; + }; + systemd.services.systemd-network-generator.wantedBy = [ "sysinit.target" ]; systemd.storePaths = [ |