0

So I've got an EC2 instance with a user-data script, that is running from a snapshot turned to a custom AMI. It uses cloud-boothook, because custom AMI's don't trigger user-data, as they're not being launched for the first time.

I really need to have a clear output of user-data execution to debug any NPM failures in the future.

However neither cloud-init.log or cloud-init-output.log contain anything from script execution.

There's also no boot.log present, as some other solutions refer to it.

#cloud-boothook
#!/bin/bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
...
npm i
npm run build
...

Below you may see /var/log/ contents

var log content

1 Answer 1

0

I ran into the same problem, and I can see in the cloud-init source code that stdout and stderr for boothook scripts are just thrown away because the default is capture=True on subp.subp. Perhaps this is intentional since boothooks run on every boot and the logs could grow without bound?

I think your only option is to redirect stdout and stdin, either by invoking yourself with redirections (and an env var to prevent recursion), or replace handles in place with something like:

# Close standard output file descriptor
exec 1<&-
# Close standard error file descriptor
exec 2<&-

# Open standard output as $LOG_FILE file for read and write.
exec 1<>$LOG_FILE

# Redirect standard error to standard output
exec 2>&1

echo "This line will appear in $LOG_FILE, not go to original stderr"

source code:

https://github.com/canonical/cloud-init/blob/bae9b11da9ed7dd0b16fe5adeaf4774b7cc628cf/cloudinit/handlers/boot_hook.py#L51

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.