2

As part of my cloud-init, I need to download a large file (ie. a 6GB toolchain / SDK). This step is executed through runcmd and takes 3-5 minutes, which is about half of the time of the initialization process.

Is it possible to at least start the download in the background earlier (ie, as part of bootcmd) and proceed with the rest of initialization (ie, apt-get install ...)?

Adam Lee
  • 2,983
  • 7
  • 35
  • 47

1 Answers1

0

Yes, that is certainly possible. E.g., given the following cloud-config:

#cloud-config
bootcmd:
 - echo 'Starting foreground sleep' >> /var/tmp/log
 - date +%s >> /var/tmp/log
 - sleep 5
 - date +%s >> /var/tmp/log

 - echo 'Starting background sleep' >> /var/tmp/log
 - date +%s >> /var/tmp/log
 - sleep 10 &
 - date +%s >> /var/tmp/log

I get this kind of result:

cat /var/tmp/log
Starting foreground sleep
1613538543
1613538548
Starting background sleep
1613538548
1613538548

Increasing the background sleep has no effect on the amount of time it takes cloud-init to finish. A background wget should work similarly.

That said, this isn't really what bootcmd was designed for. If you check the cloud-init docs, it specifies that bootcmd should only be used for things that could not be done later in the boot process. Some fairly major setup tasks (including disk setup) can still happen after bootcmd runs, so starting some large downloads that early during boot may not be a wise choice.

The runcmd module should run before any of the apt installs. You can verify with cloud-init analyze show on your cloud instance. Unless you have a really good reason to use bootcmd, you should probably just stick with runcmd.

falcojr
  • 1,299
  • 1
  • 10
  • 18