From aeaa8bc5da84d5b339c86a7b429e5b9accf8e1ae Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Tue, 9 Nov 2021 14:25:10 -0500 Subject: [PATCH] Fix cloud-init service-startup dep. loop In GCP, there are google services that must start on boot but we also rely on the more generic cloud-init services to setup the VM. Specifically, this is necessary to attend to rootfs resizing properly before testing. However, there is a dependency loop created when both are installed, that will result in messages like: ...network-online.target: Found ordering cycle on \ cloud-init.service/start ...network-online.target: Found dependency on \ google-network-daemon.service/start ...network-online.target: Found dependency on \ google-instance-setup.service/start ...network-online.target: Found dependency on \ network-online.target/start ...network-online.target: Job cloud-init.service/start \ deleted to break ordering cycle starting with \ network-online.target/start Previously, this was addressed by depositing a customized cloud-init.service file for Fedora VMs. However, at some point in the past this step was dropped. Restore it, but with a few sed-commands instead of hard-coding a new service file in this repo. Also, add a header-comment to this and another custom service file to indicate where they came from. Signed-off-by: Chris Evich --- base_images/fedora-cloud-init.service | 20 -------------------- base_images/fedora_base-setup.sh | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 21 deletions(-) delete mode 100644 base_images/fedora-cloud-init.service diff --git a/base_images/fedora-cloud-init.service b/base_images/fedora-cloud-init.service deleted file mode 100644 index 4d2197d8..00000000 --- a/base_images/fedora-cloud-init.service +++ /dev/null @@ -1,20 +0,0 @@ -[Unit] -Description=Initial cloud-init job (metadata service crawler) -DefaultDependencies=no -Wants=cloud-init-local.service -After=cloud-init-local.service -Wants=google-network-daemon.service -After=google-network-daemon.service -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 diff --git a/base_images/fedora_base-setup.sh b/base_images/fedora_base-setup.sh index f30a23d3..623a38d3 100644 --- a/base_images/fedora_base-setup.sh +++ b/base_images/fedora_base-setup.sh @@ -41,6 +41,20 @@ install_automation_tooling if ! ((CONTAINER)); then custom_cloud_init + # Be kind to humans, indicate where generated files came from + sourcemsg="### File generated during VM Image build by $(basename $SCRIPT_FILEPATH)" + + if ((OS_RELEASE_VER<35)); then + # The packaged cloud-init.service unit has a dependency loop + # vs google-network-daemon.service. Fix this by forcing cloud-init + # to run after. + CLOUD_SERVICE_PATH="systemd/system/cloud-init.service" + echo "$sourcemsg" > /etc/$CLOUD_SERVICE_PATH + sed -r -e \ + 's/Before=network-online.target/After=google-network-daemon.service' \ + /lib/$CLOUD_SERVICE_PATH >> /etc/$CLOUD_SERVICE_PATH + fi + # ref: https://cloud.google.com/compute/docs/startupscript # The mechanism used by Cirrus-CI to execute tasks on the system is through an # "agent" process launched as a GCP startup-script (from the metadata service). @@ -50,9 +64,10 @@ if ! ((CONTAINER)); then # run with the proper contexts. METADATA_SERVICE_CTX=unconfined_u:unconfined_r:unconfined_t:s0 METADATA_SERVICE_PATH=systemd/system/google-startup-scripts.service + echo "$sourcemsg" > /etc/systemd/system/cloud-init.service sed -r -e \ "s/^Type=oneshot/Type=oneshot\nSELinuxContext=$METADATA_SERVICE_CTX/" \ - /lib/$METADATA_SERVICE_PATH > /etc/$METADATA_SERVICE_PATH + /lib/$METADATA_SERVICE_PATH >> /etc/$METADATA_SERVICE_PATH fi if [[ "$OS_RELEASE_ID" == "fedora" ]] && ((OS_RELEASE_VER>=33)); then