Skip to content

Commit

Permalink
Fix cloud-init service-startup dep. loop
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cevich committed Nov 9, 2021
1 parent b7ecbe0 commit aeaa8bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
20 changes: 0 additions & 20 deletions base_images/fedora-cloud-init.service

This file was deleted.

17 changes: 16 additions & 1 deletion base_images/fedora_base-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand Down

0 comments on commit aeaa8bc

Please sign in to comment.