From b9ef830add2449ae00174113c916db6b818aea13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?= Date: Tue, 26 Mar 2024 15:19:34 +0000 Subject: [PATCH] apply: restart networkd instead of reload/reconfigure Due to systemd-networkd bugs, reload/reconfigure was not working in some cases. Instead, restart the service if the configuration has changed (LP#2058976). --- netplan_cli/cli/commands/apply.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/netplan_cli/cli/commands/apply.py b/netplan_cli/cli/commands/apply.py index 9c88a3cdd..295866079 100644 --- a/netplan_cli/cli/commands/apply.py +++ b/netplan_cli/cli/commands/apply.py @@ -273,15 +273,20 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state # exclude the special 'netplan-ovs-cleanup.service' unit netplan_ovs = [os.path.basename(f) for f in glob.glob('/run/systemd/system/*.wants/netplan-ovs-*.service') if not f.endswith('/' + OVS_CLEANUP_SERVICE)] - # Run 'systemctl start' command synchronously, to avoid race conditions + # Run 'systemctl (re)start' command synchronously, to avoid race conditions # with 'oneshot' systemd service units, e.g. netplan-ovs-*.service. - try: - utils.networkctl_reload() - utils.networkctl_reconfigure(utils.networkd_interfaces()) - except subprocess.CalledProcessError: - # (re-)start systemd-networkd if it is not running, yet - logging.warning('Falling back to a hard restart of systemd-networkd.service') - utils.systemctl('restart', ['systemd-networkd.service'], sync=True) + # + # In the past, calls to networkctl_reload/networkctl_reconfigure + # were tried, but due maybe to systemd-networkd bugs, they were not + # working as expected: the interface was getting initially the + # expected state, but after some minutes it ignored the state of + # /run/systemd/network/ and used the configuration read when the + # service was started. This happened in the case of removed + # .network files. Looking at files in + # /run/systemd/netif/links/, the internal state seemed to keep + # removed files in NETWORK_FILE= (see LP#2058976). + logging.info('Restarting systemd-networkd.service') + utils.systemctl('restart', ['systemd-networkd.service'], sync=True) # 1st: execute OVS cleanup, to avoid races while applying OVS config utils.systemctl('start', [OVS_CLEANUP_SERVICE], sync=True) # 2nd: start all other services