Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hotplugd.socket): remove basic.target as dependency #5722

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

aciba90
Copy link
Contributor

@aciba90 aciba90 commented Sep 20, 2024

Proposed Commit Message

fix(hotplugd.socket): remove basic.target as dependency

In 62ace19d679 we moved cloud-init-hotplugd.socket earlier in boot,
after cloud-config.target. But we didn't remove the dependencies added
by default and this might conflict with other units producing
non-solvable ordering cycles, see #2081124.

Remove the default dependency on basic.target added by systemd.

LP: #2081124

Additional Context

I have manually tested this on and image produced by https://cdimage.ubuntu.com/noble/daily-live/20240920/, modifying the target system prior to first-booting.

Test Steps

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

In 62ace19 we moved cloud-init-hotplugd.socket earlier in boot,
after cloud-config.target. But we didn't remove the dependencies added
by default and this might conflict with other units producing
non-solvable ordering cycles, see #2081124.

Remove the default dependency on basic.target added by systemd.

LP: #2081124
@blackboxsw blackboxsw self-assigned this Sep 20, 2024
@@ -5,6 +5,9 @@
# Known bug with an enforcing SELinux policy: LP: #1936229
[Unit]
Description=cloud-init hotplug hook socket
DefaultDependencies=no
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that image launches in virt-manager in Oracular Daily Desktop images from 20240916 with livecd-rootfs fix that we can see ordering cycle issues on Oracular too.

# Run on an Oracular custom image with proper cloud-init-network.service drop-in override from livecd-rootfs
+ cat /cdrom/.disk/info
Ubuntu 24.10 "Oracular Oriole" - Daily amd64 (20240916)+ echo Confirm expected livecd-rootfs dropin orders cloud-init-network.service After=NetworkManager.service
Confirm expected livecd-rootfs dropin orders cloud-init-network.service After=NetworkManager.service
+ cat /etc/systemd/system/cloud-init-network.service
# Based on cloud-init 24.3 for Desktop LiveCD
# Redact sysinit.target from Before, add After=NetworkManager*.service
# (LP: #2008952)
[Unit]
# https://cloudinit.readthedocs.io/en/latest/explanation/boot.html
Description=Cloud-init: Network Stage
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
After=networking.service
After=NetworkManager.service NetworkManager-wait-online.service
Before=network-online.target
Before=sshd-keygen.service
Before=sshd.service
Before=systemd-user-sessions.service
# Before=sysinit.target Redacted due to NetworkManager.service dbus depends
Before=shutdown.target
Conflicts=shutdown.target
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled

[Service]
Type=oneshot
# This service is a shim which preserves systemd ordering while allowing a
# single Python process to run cloud-init's logic. This works by communicating
# with the cloud-init process over a unix socket to tell the process that this
# stage can start, and then wait on a return socket until the cloud-init
# process has completed this stage. The output from the return socket is piped
# into a shell so that the process can send a completion message (defaults to
# "done", otherwise includes an error message) and an exit code to systemd.
ExecStart=sh -c 'echo "start" | netcat -Uu -W1 /run/cloud-init/share/network.sock -s /run/cloud-init/share/network-return.sock | sh'
RemainAfterExit=yes
TimeoutSec=0

# Output needs to appear in instance console output
StandardOutput=journal+console

[Install]
WantedBy=cloud-init.target
+ systemctl show -p Before,After cloud-init-network.service --no-pager
Before=network-online.target sshd.service systemd-user-sessions.service sshd-keygen.service cloud-config.target shutdown.target
After=systemd-networkd-wait-online.service system.slice networking.service systemd-journald.socket NetworkManager.service cloud-init-local.service NetworkManager-wait-online.service
+ systemctl show -p Before,After cloud-init-hotplugd.socket --no-pager
Before=sockets.target shutdown.target cloud-init-hotplugd.service
After=-.mount system.slice cloud-config.target sysinit.target
+ systemctl show -p Before,After cloud-init-hotplugd.service --no-pager
Before=shutdown.target
After=systemd-journald.socket cloud-init-hotplugd.socket basic.target system.slice cloud-init.target sysinit.target
+ journalctl -b 0
+ grep ordering cycle
Sep 20 20:25:26 ubuntu systemd[1]: basic.target: Found ordering cycle on sockets.target/start
Sep 20 20:25:26 ubuntu systemd[1]: basic.target: Job sockets.target/start deleted to break ordering cycle starting with basic.target/start

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also applied both livecd-rootfs fix and cloud-init fix from 5722

+ cat /cdrom/.disk/info
Ubuntu 24.10 "Oracular Oriole" - Daily amd64 (20240916)+ echo Confirm expected livecd-rootfs dropin orders cloud-init-network.service After=NetworkManager.service
Confirm expected livecd-rootfs dropin orders cloud-init-network.service After=NetworkManager.service
+ cat /etc/systemd/system/cloud-init-network.service
# Based on cloud-init 24.3 for Desktop LiveCD
# Redact sysinit.target from Before, add After=NetworkManager*.service
# (LP: #2008952)
[Unit]
# https://cloudinit.readthedocs.io/en/latest/explanation/boot.html
Description=Cloud-init: Network Stage
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
After=networking.service
After=NetworkManager.service NetworkManager-wait-online.service
Before=network-online.target
Before=sshd-keygen.service
Before=sshd.service
Before=systemd-user-sessions.service
# Before=sysinit.target Redacted due to NetworkManager.service dbus depends
Before=shutdown.target
Conflicts=shutdown.target
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled

[Service]
Type=oneshot
# This service is a shim which preserves systemd ordering while allowing a
# single Python process to run cloud-init's logic. This works by communicating
# with the cloud-init process over a unix socket to tell the process that this
# stage can start, and then wait on a return socket until the cloud-init
# process has completed this stage. The output from the return socket is piped
# into a shell so that the process can send a completion message (defaults to
# "done", otherwise includes an error message) and an exit code to systemd.
ExecStart=sh -c 'echo "start" | netcat -Uu -W1 /run/cloud-init/share/network.sock -s /run/cloud-init/share/network-return.sock | sh'
RemainAfterExit=yes
TimeoutSec=0

# Output needs to appear in instance console output
StandardOutput=journal+console

[Install]
WantedBy=cloud-init.target
+ systemctl show -p Before,After cloud-init-network.service --no-pager
Before=sshd.service shutdown.target network-online.target systemd-user-sessions.service sshd-keygen.service cloud-config.target
After=NetworkManager.service systemd-journald.socket system.slice cloud-init-local.service networking.service NetworkManager-wait-online.service systemd-networkd-wait-online.service
+ systemctl show -p Before,After cloud-init-hotplugd.socket --no-pager
Before=shutdown.target cloud-init-hotplugd.service
After=-.mount cloud-config.target system.slice
+ systemctl show -p Before,After cloud-init-hotplugd.service --no-pager
Before=shutdown.target
After=cloud-init.target systemd-journald.socket basic.target cloud-init-hotplugd.socket sysinit.target system.slice
+ journalctl -b 0
+ grep ordering cycle
+ cat /lib/systemd/system/cloud-init-hotplugd.socket 
# cloud-init-hotplugd.socket listens on the FIFO file
# /run/cloud-init/hook-hotplug-cmd which is created during a udev network
# add or remove event as processed by 90-cloud-init-hook-hotplug.rules.

# Known bug with an enforcing SELinux policy: LP: #1936229
[Unit]
Description=cloud-init hotplug hook socket
DefaultDependencies=no
Before=shutdown.target
Conflicts=shutdown.target
After=cloud-config.target
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled

[Socket]
ListenFIFO=/run/cloud-init/hook-hotplug-cmd

[Install]
WantedBy=cloud-config.target

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ordering cycles seen in ephemeral boot from journalctl in the second run, also we see sysinit.target dropped from hotplugd.socket due to the correction of DefaultDependencies=no

+ systemctl show -p Before,After cloud-init-hotplugd.socket --no-pager
Before=shutdown.target cloud-init-hotplugd.service
After=-.mount cloud-config.target system.slice

Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks Alberto for the quick fix. Uploading this to Oracular as this is beta bug worthy!

@@ -5,6 +5,9 @@
# Known bug with an enforcing SELinux policy: LP: #1936229
[Unit]
Description=cloud-init hotplug hook socket
DefaultDependencies=no
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ordering cycles seen in ephemeral boot from journalctl in the second run, also we see sysinit.target dropped from hotplugd.socket due to the correction of DefaultDependencies=no

+ systemctl show -p Before,After cloud-init-hotplugd.socket --no-pager
Before=shutdown.target cloud-init-hotplugd.service
After=-.mount cloud-config.target system.slice

@blackboxsw blackboxsw merged commit b36ddb1 into canonical:main Sep 20, 2024
21 checks passed
@aciba90 aciba90 deleted the lp2081124-fix-dep-cycle branch September 23, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants