Where to find logs for a cloud-init user-data script?

后端 未结 3 1537
温柔的废话
温柔的废话 2021-02-18 19:52

I\'m initializing spot instances running a derivative of the standard Ubuntu 13.04 AMI by pasting a shell script into the user-data field.

This works. The script runs. B

3条回答
  •  悲&欢浪女
    2021-02-18 20:33

    so I tried to replicate your problem. Usually I work in Cloud Config and therefore I just created a simple test user-data script like this:

    #!/bin/sh
    
    echo "Hello World.  The time is now $(date -R)!" | tee /root/output.txt
    
    echo "I am out of the output file...somewhere?"
    
    yum search git    # just for fun
    
    ls
    
    exit 0
    

    Notice that, with CloudInit shell scripts, the user-data "will be executed at rc.local-like level during first boot. rc.local-like means 'very late in the boot sequence'" After logging in into my instance (a Scientific Linux machine) I first went to /var/log/boot.log and there I found:

    Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200! I am

    out of the file. Log file somewhere? Loaded plugins: changelog, kernel-module, priorities, protectbase, security, : tsflags, versionlock 126 packages excluded due to repository priority protections 9 packages excluded due to repository protections ^Mepel/pkgtags
    | 581 kB 00:00

    =============================== N/S Matched: git =============================== ^[[1mGit^[[0;10mPython.noarch : Python ^[[1mGit^[[0;10m Library c^[[1mgit^[[0;10m.x86_64 : A fast web interface for ^[[1mgit^[[0;10m

    ...

    ... (more yum search output)

    ...

    bin etc lib lost+found mnt proc sbin srv tmp var

    boot dev home lib64 media opt root selinux sys usr

    (other unrelated stuff)

    So, as you can see, my script ran and was rightly logged. Also, as expected, I had my forced log 'output.txt' in /root/output.txt with the content:

    Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200!

    So...I am not really sure what is happening in you script. Make sure you're exiting the script with

    exit 0   #or some other code
    

    If it still doesn't work, you should provide more info, like your script, your boot.log, your /etc/rc.local, and your cloudinit.log. btw: what is your cloudinit version?

提交回复
热议问题