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:


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:

 - 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:


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?

  • Do you know for sure the whole userdata script isn't running? Does something like echo "CLUSTER=FOO" > /etc/testfile fail too? – TylerW Aug 28 '16 at 2:53
  • @TylerW Yeah, I've used scripts as simple as touch /tmp/foo and used the example logging script here but neither run at all when the per-boot script is in place. If the per-boot script is absent they both run fine. – richid Aug 29 '16 at 14:51

Amazon' userdata is only executed the first time a machine is started. If you create a custom ami the machine which was used to create this image was already started once.

You might try to setup your MIME as to run it every time on boot. Google helps with that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.