apt-daily-upgrade.service uses `apt-helper wait-online` as an ExecStartPre step. On multi-NIC systems with systemd-networkd this helper directly calls systemd-networkd-wait-online in strict mode, waiting for all managed links to become online. On boards with multiple Ethernet ports where some interfaces are commonly unplugged, this results in repeated timeouts and causes apt-daily-upgrade / unattended-upgrades to abort, even when at least one interface is already fully routable. Replace the ExecStartPre step with a direct invocation of systemd-networkd-wait-online using `--any`, allowing the service to proceed as soon as one interface is online. This preserves the intent of waiting for network availability while making the behavior robust on multi-NIC and router-style systems.
57 lines
3.3 KiB
Bash
57 lines
3.3 KiB
Bash
#
|
|
# Extension to manage network interfaces with systemd-networkd + Netplan
|
|
#
|
|
function extension_prepare_config__install_systemd_networkd() {
|
|
# Sanity check
|
|
if [[ "${NETWORKING_STACK}" != "systemd-networkd" ]]; then
|
|
exit_with_error "Extension: ${EXTENSION}: requires NETWORKING_STACK='systemd-networkd', currently set to '${NETWORKING_STACK}'"
|
|
fi
|
|
|
|
display_alert "Extension: ${EXTENSION}: Adding extra packages to image" "netplan.io" "info"
|
|
add_packages_to_image netplan.io
|
|
}
|
|
|
|
function pre_install_kernel_debs__configure_systemd_networkd() {
|
|
display_alert "Extension: ${EXTENSION}: Enabling systemd-networkd" "" "info"
|
|
|
|
# Enable networkd and resolved
|
|
# Very likely not needed to enable manually since these services are enabled by default
|
|
chroot_sdcard systemctl enable systemd-networkd.service || display_alert "Failed to enable systemd-networkd.service" "" "wrn"
|
|
chroot_sdcard systemctl enable systemd-resolved.service || display_alert "Failed to enable systemd-resolved.service" "" "wrn"
|
|
|
|
# Copy network config files into the appropriate folders
|
|
display_alert "Extension: ${EXTENSION}: Configuring" "systemd-networkd and Netplan" "info"
|
|
local netplan_config_src_folder="${EXTENSION_DIR}/config-networkd/netplan/"
|
|
local netplan_config_dst_folder="${SDCARD}/etc/netplan/"
|
|
|
|
run_host_command_logged cp -v "${netplan_config_src_folder}"* "${netplan_config_dst_folder}"
|
|
|
|
local networkd_config_src_folder="${EXTENSION_DIR}/config-networkd/systemd/network/"
|
|
local networkd_config_dst_folder="${SDCARD}/etc/systemd/network/"
|
|
|
|
run_host_command_logged cp -v "${networkd_config_src_folder}"* "${networkd_config_dst_folder}"
|
|
|
|
local networkd_conf_d_config_src_folder="${EXTENSION_DIR}/config-networkd/systemd/networkd.conf.d/"
|
|
local networkd_conf_d_config_dst_folder="${SDCARD}/etc/systemd/networkd.conf.d/"
|
|
|
|
mkdir -p "${networkd_conf_d_config_dst_folder}" # This doesn't exist by default, create it
|
|
run_host_command_logged cp -v "${networkd_conf_d_config_src_folder}"* "${networkd_conf_d_config_dst_folder}"
|
|
|
|
# wait-online waits for all managed interfaces to become online. We ship DHCP on all interfaces and if all are not connected it will timeout
|
|
local networkd_wait_online_override_src_folder="${EXTENSION_DIR}/config-networkd/systemd/system/systemd-networkd-wait-online.service.d/"
|
|
local networkd_wait_online_override_dst_folder="${SDCARD}/etc/systemd/system/systemd-networkd-wait-online.service.d/"
|
|
|
|
mkdir -p "${networkd_wait_online_override_dst_folder}" # This doesn't exist by default, create it
|
|
run_host_command_logged cp -v "${networkd_wait_online_override_src_folder}"* "${networkd_wait_online_override_dst_folder}"
|
|
|
|
# since daily upgrade is not calling systemd-networkd-wait-online.service (but it should) we need to patch that service too
|
|
local apt_daily_upgrade_service_override_src_folder="${EXTENSION_DIR}/config-networkd/systemd/system/apt-daily-upgrade.service.d/"
|
|
local apt_daily_upgrade_service_override_dst_folder="${SDCARD}/etc/systemd/system/apt-daily-upgrade.service.d/"
|
|
|
|
mkdir -p "${apt_daily_upgrade_service_override_dst_folder}" # This doesn't exist by default, create it
|
|
run_host_command_logged cp -v "${apt_daily_upgrade_service_override_src_folder}"* "${apt_daily_upgrade_service_override_dst_folder}"
|
|
|
|
# Change the file permissions according to https://netplan.readthedocs.io/en/stable/security/
|
|
chmod -v 600 "${SDCARD}"/etc/netplan/*
|
|
}
|