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