用户数据脚本无故失败 [英] user data scripts fails without giving reason

查看:18
本文介绍了用户数据脚本无故失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Web 控制台启动 Amazon Linux 实例 (ami-fb8e9292),将数据粘贴到用户数据框中以在启动时运行脚本.如果我使用亚马逊提供的 示例 来启动网络服务器,它的工作原理.但是当我运行我自己的脚本(也是一个 #!/bin/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.

如果我查看 var/log/cloud-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 进入实例并 sudo su 并直接执行 shell 脚本:

If I ssh into the instance and sudo su and execute the shell script directly:

/var/lib/cloud/instance/scripts/part-001

然后它运行良好.此外,如果我模拟 cloud-init 运行它的方式,它也可以工作:

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?

推荐答案

我不确定是否每个人都会遇到这种情况,但是我遇到了这个问题并且能够通过更改我的第一行来解决它从此:

I'm not sure if this is going to be the case for everyone, but I was having this issue and was able to fix it by changing my first line from this:

#!/bin/bash -e -v

就这样:

#!/bin/bash

当然,现在我的脚本失败了,我不知道它能走多远,但至少我通过了它而不是运行它.:)

Of course, now my script is failing and I have no idea how far it's getting, but at least I got past it not running it at. :)

这篇关于用户数据脚本无故失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆