Skip to content

Commit

Permalink
apply: restart networkd instead of reload/reconfigure
Browse files Browse the repository at this point in the history
Due to systemd-networkd bugs, reload/reconfigure was not working in
some cases. Instead, restart the service if the configuration has
changed (LP#2058976).
  • Loading branch information
alfonsosanchezbeato committed Mar 26, 2024
1 parent 2d3f904 commit b9ef830
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions netplan_cli/cli/commands/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<num>, 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
Expand Down

0 comments on commit b9ef830

Please sign in to comment.