cloud-init.service: systemd ordering after after NetworkManager

Autoinstall directives can be provided on the grub cmdline to
cloud-init via kernel parameters like the following:
 autoinstall 'ds=nocloud-net;s=http://somedomain/'

In order to support DNS resolution for NoCloud datasource at
datasource discovery time, cloud-init.service needs to be
orderered after NetworkManager.service and
NetworkManager-wait-online.service
which will have brought up applicable NICs.

Since NetworkManager is After=dbus.service, the cloud-init.service
avoids systemd ordering cycles by also dropping
Before=sysinit.target when it adds, After=NetworkManager.service and
After=NetworkManager-wait-online.service

Add this file overlay for /lib/systemd/system/cloud-init.service
because systemd drop-in files can only add constraints and not
drop prexisting service constraints.

Also add an AUTOMATION_HEADER comment to any generated files to
add discoverability in the event of future bugs/concerns.

LP: #2008952
ui-by-default-wip
Chad Smith 2 years ago
parent e1d6746467
commit fba5be17fd

@ -4,6 +4,8 @@
imagesize=${IMAGE_SIZE:-2361393152} imagesize=${IMAGE_SIZE:-2361393152}
fs_label="${FS_LABEL:-rootfs}" fs_label="${FS_LABEL:-rootfs}"
AUTOMATION_HEADER="# Automatically generated by installer build process"
rootfs_dev_mapper= rootfs_dev_mapper=
loop_device= loop_device=
loop_raw= loop_raw=
@ -1010,6 +1012,7 @@ EOF
# inform cloud-init of the same (LP: #1982855) # inform cloud-init of the same (LP: #1982855)
mkdir -p chroot/etc/cloud/cloud.cfg.d mkdir -p chroot/etc/cloud/cloud.cfg.d
cat <<EOF > chroot/etc/cloud/cloud.cfg.d/99-installer-use-networkmanager.cfg cat <<EOF > chroot/etc/cloud/cloud.cfg.d/99-installer-use-networkmanager.cfg
${AUTOMATION_HEADER}
# Let NetworkManager manage all devices on this system # Let NetworkManager manage all devices on this system
system_info: system_info:
network: network:
@ -1017,6 +1020,50 @@ system_info:
activators: ['network-manager'] activators: ['network-manager']
EOF EOF
# Position cloud-init.service After=NetworkManager.service.
# (LP: #2008952).
# We override the entire cloud-init.service definition because
# systemd drop-in files only allow adding Before/After constraints
# yet we are dropping the Before=sysinit.target from the upstream
# cloud-init.service.
# This override can be dropped when NetworkManager.service can run
# Before=sysinit.target when it drops strict dbus.service dependency.
cat <<EOF > chroot/lib/systemd/system/cloud-init.service
${AUTOMATION_HEADER}
# Based on cloud-init 23.1 for Desktop LiveCD
[Unit]
Description=Initial cloud-init job (metadata service crawler)
DefaultDependencies=no
Wants=cloud-init-local.service
Wants=sshd-keygen.service
Wants=sshd.service
After=cloud-init-local.service
After=systemd-networkd-wait-online.service
# Installer Added After=NetworkManager* ordering
After=NetworkManager.service
After=NetworkManager-wait-online.service
After=networking.service
Before=network-online.target
Before=sshd-keygen.service
Before=sshd.service
# Before=sysinit.target Installer removed to allow for NM dependency
Before=shutdown.target
Conflicts=shutdown.target
Before=systemd-user-sessions.service
[Service]
Type=oneshot
ExecStart=/usr/bin/cloud-init init
RemainAfterExit=yes
TimeoutSec=0
# Output needs to appear in instance console output
StandardOutput=journal+console
[Install]
WantedBy=cloud-init.target
EOF
# Allow cloud-init clean to inform of strict network-manager config # Allow cloud-init clean to inform of strict network-manager config
mkdir -p chroot/etc/cloud/clean.d mkdir -p chroot/etc/cloud/clean.d
cat <<EOF > chroot/etc/cloud/clean.d/99-installer-use-networkmanager cat <<EOF > chroot/etc/cloud/clean.d/99-installer-use-networkmanager

Loading…
Cancel
Save