Skip to content

Improve systemd ordering for cloud-init-local to preserve /var mount #70

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

Open
wants to merge 1 commit into
base: jammy-cloud-init-fixup
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status (-e),
# treat unset variables as an error and exit immediately (-u),
# and ensure that a pipeline fails if any part fails (-o pipefail).
set -euo pipefail

# Ensure that cloud-init-local requires /var/lib/cloud to be mounted
cat > /etc/systemd/system/cloud-init-local.service <<EOF
# Display a message indicating the purpose of the script
echo "Creating systemd override for cloud-init-local.service to ensure it starts after /var is mounted"

# Define the path to the systemd override directory
OVERRIDE_DIR="/etc/systemd/system/cloud-init-local.service.d"

# Create the override directory if it doesn't already exist
mkdir -p "${OVERRIDE_DIR}"

# Define the path to the override file
OVERRIDE_FILE="${OVERRIDE_DIR}/override.conf"

# Write the override configuration
cat <<EOF >"${OVERRIDE_FILE}"
[Unit]
Requires=var.mount
After=var.mount
RequiresMountsFor=/var/lib/cloud
EOF

echo "Applied fixup for cloud-init-local"
# Ensure correct permissions
chmod 755 "${OVERRIDE_DIR}"
chmod 644 "${OVERRIDE_FILE}"

# Display a message indicating that the override has been created
echo "Systemd override for cloud-init-local.service created successfully"