[Unit]
# https://docs.cloud-init.io/en/latest/explanation/boot.html
Description=Cloud-init: Final Stage
After=network-online.target time-sync.target cloud-config.service rc-local.service
After=multi-user.target
Before=apt-daily.service
Wants=network-online.target cloud-config.service
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" | nc -Uu -W1 /run/cloud-init/share/final.sock -s /run/cloud-init/share/final-return.sock | sh'
RemainAfterExit=yes
TimeoutSec=0
TasksMax=infinity

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

[Install]
WantedBy=cloud-init.target
