用户数据脚本失败不给理由 [英] user data scripts fails without giving reason
问题描述
我开始使用Web控制台亚马逊Linux实例(AMI-fb8e9292),粘贴数据到用户数据中在启动时运行的脚本。如果我使用例如亚马逊给启动Web服务器,它的工作原理。但是,当我跑我自己的脚本(也有#!/斌/ bash的
脚本),它不会运行。
I am starting a Amazon Linux instance (ami-fb8e9292) using the web console, pasting data into the user data box to run a script upon startup. If I use the example given by amazon to start a web server, it works. But when I run my own script (also a #!/bin/bash
script), it does not get run.
如果我看在无功/日志/云init.log
,它提供了有关该主题的有用信息:
If I look in var/log/cloud-init.log
, it gives no useful information on the topic:
May 22 21:06:12 cloud-init[1286]: util.py[DEBUG]: Running command ['/var/lib/cloud/instance/scripts/part-001'] with allowed return codes [0] (shell=True, capture=False)
May 22 21:06:16 cloud-init[1286]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [2]
May 22 21:06:16 cloud-init[1286]: util.py[DEBUG]: Failed running /var/lib/cloud/instance/scripts/part-001 [2]
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/cloudinit/util.py", line 637, in runparts
subp([exe_path], capture=False, shell=True)
File "/usr/lib/python2.6/site-packages/cloudinit/util.py", line 1528, in subp
cmd=args)
ProcessExecutionError: Unexpected error while running command.
Command: ['/var/lib/cloud/instance/scripts/part-001']
Exit code: 2
Reason: -
Stdout: ''
Stderr: ''
如果我SSH连接实例和须藤苏
,然后直接执行shell脚本:
If I ssh into the instance and sudo su
and execute the shell script directly:
/var/lib/cloud/instance/scripts/part-001
那么它运行良好。此外,它的工作原理,如果我模仿的方式云初始化运行它:
then it runs fine. Also, it works if I emulate the way cloud-init runs it:
python
>>> import cloudinit.util
>>> cloudinit.util.runparts("/var/lib/cloud/instance/scripts/")
无论使用这些方法,如果我故意将错误引入脚本,然后它产生的错误信息。如何调试选择性缺乏有用的调试输出?
Using either of those methods, if I intentionally introduce errors into the script then it produces error messages. How can I debug the selective absence of useful debugging output?
推荐答案
我有一个类似的问题,我能得到周围。我意识到,环境变量EC2_HOME不会设置为sudo的。我在做我的configset了一堆东西,它使用AWS CLI并为这些工作,EC2_HOME需要设置。于是,我走进去,到处都是我的configset和userData删除sudo的。 早些时候,当我打这个问题,我的UserData看起来像:
I had a similar issue and I was able to get around it. I realized that the environment variables EC2_HOME would not be setup for the sudo. I was doing a bunch of stuff in my configset which uses aws cli and for these to work, the EC2_HOME needs to be setup. So, I went in and removed sudo everywhere in my configset and UserData. Earlier when I was hitting the issue, my UserData looked like:
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n",
"sudo yum update -y aws-cfn-bootstrap\n",
"# Install the files and packages and run the commands from the metadata\n",
"sudo /opt/aws/bin/cfn-init -v --access-key ", { "Ref" : "IAMUserAccessKey" }, " --secret-key ", { "Ref" : "SecretAccessKey" },
" --stack ", { "Ref" : "AWS::StackName" },
" --resource NAT2 ",
" --configsets config ",
" --region ", { "Ref" : "AWS::Region" }, "\n"
]]}}
我的更改后的UserData看起来像:
My UserData after the changes looked like:
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -xe\n",
"yum update -y aws-cfn-bootstrap\n",
"# Install the files and packages and run the commands from the metadata\n",
"/opt/aws/bin/cfn-init -v --access-key ", { "Ref" : "IAMUserAccessKey" }, " --secret-key ", { "Ref" : "SecretAccessKey" },
" --stack ", { "Ref" : "AWS::StackName" },
" --resource NAT2 ",
" --configsets config ",
" --region ", { "Ref" : "AWS::Region" }, "\n"
]]}}
同样,我删除了所有的sudo的电话我是在做我的configsets
Similarly, I removed all the sudo calls I was doing in my configsets
这篇关于用户数据脚本失败不给理由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!