1

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?

richid
  • 140
  • 6
  • 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 02:53
  • @TylerW Yeah, I've used scripts as simple as `touch /tmp/foo` and used the example [logging script here](https://forums.aws.amazon.com/message.jspa?messageID=555093#jive-message-536024) 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

1 Answers1

1

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

Dave M
  • 4,514
  • 22
  • 31
  • 30
googler
  • 11
  • 1