networkd: stop all socket units to prevent socket activation restart#613
networkd: stop all socket units to prevent socket activation restart#613miharp wants to merge 1 commit intovoxpupuli:masterfrom
Conversation
|
Using a fact for getting the remaining open sockets, will not work since facts computation is done asynchronous from the puppet run. A function is needed for this. |
91c8077 to
0822e44
Compare
|
Thanks for the review @trefzer! To clarify the intent: the fact queries `systemctl list-unit-files` (unit file existence on disk) rather than `list-units` (runtime active state). Unit files are stable — they should not appear or disappear during a puppet run under normal circumstances. I guess this could be a problem when puppet installs `systemd-networkd` during the same run on a platform where it's a separate package (e.g. Debian). In that case the socket unit files wouldn't exist at fact-collection time, so no socket resources would be declared. However, on those platforms (Debian/Ubuntu with systemd < 256) there is only `systemd-networkd.socket` and it doesn't trigger the restart behaviour we're fixing — I think the problem is specific to systemd 260+ on Archlinux, where networkd is always pre-installed as part of the base system. That said, if you think a function is still the right approach here to be more robust, happy to discuss. Are you thinking of using a custom Puppet function that calls `systemctl` at catalog application time rather than collection time?" |
0822e44 to
1483c45
Compare
|
Yes I definitly think that a function is a better approach than a fact. I disagree, that it's only an Archlinux problem since Archlinux is now the first using systemd 260, but others will follow ! So implementing a generic solution should be the goal. (Sorry I rewrote know my whole reply, since function is on server !) |
Local TestingPlatform systemd versions
Archlinux is currently the only mainstream distro shipping systemd 260+. Archlinux / systemd 260+ (the bug platform)Confirmed in an Archlinux container running systemd 260: Without the fix, stopping Ubuntu 24.04 agent / systemd 255 (Vagrant)Socket units on this platform: First puppet run ( Second puppet run (idempotency check): No changes on the second run. ✓ CentOS Stream 10 agent / systemd 252 (Vagrant)No |
|
Debian testing (forky) is on systemd 260.1 (https://packages.debian.org/source/forky/systemd). The problem is not to set the sockets to 'stopped'. But if ensure is set to 'running' then all available sockets will be enabled. |
|
@trefzer Ah, I get it now, missed the fact that |
1483c45 to
388d042
Compare
On systemd 260+ (Archlinux rolling), additional socket units (systemd-networkd-varlink.socket, systemd-networkd-varlink-metrics.socket, systemd-networkd-resolve-hook.socket) cause systemd to immediately re-activate systemd-networkd.service via socket activation when it is stopped. This makes `networkd_ensure => stopped` non-idempotent on Archlinux. Add a `systemd_networkd_socket_units` fact that discovers all `systemd-networkd*.socket` unit files present on the node. The manifest iterates over them, stopping all socket units before stopping the service. This handles the current set of sockets as well as any added in future systemd versions. On platforms where systemd-networkd is not installed (RHEL/CentOS) the fact returns an empty array and no socket resources are declared. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Michael Harp <mike@mikeharp.com>
388d042 to
fb7b2b5
Compare
|
I want to point out that functions Always run on the server (except for referred functions) and facts on the agent. |
Yeah, I thought he might have been thinking about deferred functions which I always try and avoid :) |
|
@bastelfreak @trefzer ready to merge |
|
Do we know why each of the sockets does not have a so the socket would stop on service stop would be automatic. The behaviour of leaving the sockets behind is either deliberate or not. Example that uses |
|
With a bit of digging I answered my own question. Using There is |
|
Do wonder if there is ever an actual use case to stop systemd-networkd via puppet ? I mean just document that this particular one is not tested deliberately. |
|
Or this is a case of user should be aware. If they really want to stop all the network service it's up to them to also stop the sockets. Add those explicit stops to the acceptance tests. I'm not convinced trying to be smarter than what systemd is going to do is a good idea. |
Pull Request (PR) description
On systemd 260+ (Archlinux rolling), additional socket units
(
systemd-networkd-varlink.socket,systemd-networkd-varlink-metrics.socket,systemd-networkd-resolve-hook.socket) cause systemd to immediately re-activatesystemd-networkd.servicevia socket activation when it is stopped, makingnetworkd_ensure => stoppednon-idempotent.Add a
systemd_networkd_socket_unitsfact that discovers allsystemd-networkd*.socketunit files present on the node. The manifestiterates over them, stopping all socket units before stopping the service.
This handles the current set of sockets as well as any added in future
systemd versions.
On platforms where systemd-networkd is not installed (RHEL/CentOS) the fact
returns an empty array and no socket resources are declared.
This Pull Request (PR) fixes the following issues
Fixes #612