Where to find logs for a cloud-init user-data script?
我正在通过将shell脚本粘贴到用户数据字段中来初始化运行标准Ubuntu 13.04 AMI衍生版本的竞价型实例。
这有效。脚本运行。但是调试起来很困难,因为我无法弄清楚脚本输出的记录位置(如果有的话)。
我查看了/var/log/cloud-init.log,其中似乎包含许多与调试cloud-init本身相关的内容,但与我的脚本无关。我在/ var / log中摸索着,什么也没找到。
打开登录是否需要做些特别的事情?
在AWS,DigitalOcean和大多数其他云提供商中,云初始化用户数据的默认位置已经为
您可以为您的用户数据创建一个云配置文件(顶部带有"#cloud-config "),使用runcmd调用脚本,然后启用输出日志记录,如下所示:
1 | output: {all: '| tee -a /var/log/cloud-init-output.log'} |
所以我试图重复您的问题。通常,我在Cloud Config中工作,因此我只是创建了一个简单的测试用户数据脚本,如下所示:
1 2 3 4 5 6 7 8 9 10 11 | #!/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 |
请注意,使用CloudInit Shell脚本,用户数据"将在首次引导期间以类似rc.local的级别执行。rc.local-like的意思是'在引导顺序中非常晚''
登录到我的实例(科学Linux机器)后,我首先进入/var/log/boot.log,在那里我发现:
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)
因此,如您所见,我的脚本已运行并且已正确记录。
而且,正如预期的那样,我在/root/output.txt中有强制日志\\'output.txt \\',内容为:
Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200!
所以...我不太确定您的脚本中正在发生什么。
确保使用
退出脚本
1 | exit 0 #or some other code |
如果仍然无法正常工作,则应提供更多信息,例如脚本,boot.log,/ etc / rc.local和cloudinit.log。
顺便说一句:您的cloudinit版本是什么?