EC2 userdata not running with custom per-boot cloud-init script

I'm trying to start a process at boot on a Ubuntu 14 LTS AMI (ami-3bdd502c) using cloud-init's per-boot script facility and configure that process with EC2 userdata. The process has sensible defaults but I'm attempting to allow these defaults to be overridden by using EC2 userdata to write some bits to /etc/default/foo.

However, when I drop the custom per-boot script on disk (/var/lib/cloud/scripts/per-boot/run-process.sh) it executes as expected but the EC2 userdata step does not run. If I launch a version of this AMI without the per-boot script the EC2 userdata step runs as expected. It seems as if the per-boot script is clobbering the EC2 userdata step.

The EC2 userdata script I am using looks like this:

#!/bin/bash

echo "CLUSTER=foo" >> /etc/default/foo

As per /etc/cloud/cloud.cfg I would expect this step to run before the scripts-per-boot step:

cloud_final_modules:
 - rightscale_userdata
 - scripts-vendor
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 ...

Further, manually running the running the cloud-final step as well as the userdata step individually works fine

sudo cloud-init modules --mode=final
sudo cloud-init single -n rightscale_userdata

Towards the end of my investigation I noticed that when I add the #cloud-boothook directive at the top of the userdata script everything works as expected:

#cloud-boothook
#!/bin/bash

echo "CLUSTER=foo" >> /etc/default/foo

I realize that there are a dozen other ways to accomplish this but I'm really looking to understand why I'm seeing this behavior. So, what am I missing here?

1
задан 24 August 2016 в 21:30
1 ответ

Пользовательские данные Amazon выполняются только при первом запуске машины. Если вы создаете пользовательский ami , машина, которая использовалась для создания этого образа, уже была запущена один раз.

Вы можете попробовать настроить MIME так, чтобы он запускался каждый раз при загрузке. Google помогает в этом

1
ответ дан 3 December 2019 в 23:42

Теги

Похожие вопросы