【问题标题】:elastic beanstalk configuration error弹性豆茎配置错误
【发布时间】:2014-02-27 01:26:44
【问题描述】:

我正在尝试在 php 5.5 容器中的弹性 beantalk 上启动应用程序。有 3 个环境 dev、staging 和 production。从命令行设置环境变量时,您无法区分环境,因此我使用 aws support 建议的解决方法,即在部署时运行 shell 脚本来设置变量,具体取决于另一个变量的存在我可以根据环境而有所不同

.当我部署我的应用程序时,.ebextensions/ 中有一个配置文件,就像这样

container_commands:
  command01:
    command: "./.ebextensions/setEnvVars.sh"

shell 脚本也在 .ebextensions 中,看起来像这样

#!/bin/bash
case "$PARAM1" in
        "development")
                echo -e "SetEnv APP_ENV development\n
                         SetEnv DB_HOST *******\n
                         SetEnv DB_NAME *******\n
                         SetEnv DB_USERNAME *******\n
                         SetEnv DB_PASSWORD *******\n" > .htaccess
                ;;
        "production")
                echo -e "SetEnv APP_ENV production\n
                         SetEnv DB_HOST *******\n
                         SetEnv DB_NAME *******\n
                         SetEnv DB_USERNAME *******\n
                         SetEnv DB_PASSWORD *******\n" > .htaccess
                ;;
        "staging")
                echo -e "SetEnv APP_ENV staging\n
                         SetEnv DB_HOST *******\n
                         SetEnv DB_NAME *******\n
                         SetEnv DB_USERNAME *******\n
                         SetEnv DB_PASSWORD *******\n" > .htaccess
                ;;
esac

if [ -f .htaccess ]; then
        chmod 644 .htaccess
fi

当应用部署时出现此错误

[Instance: i-400fc60f Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command command01 failed .

这就是我认为来自日志的相关 ecert

2014-02-03 12:54:25,531 [INFO] (1923 MainThread) [command.py-130] [root command execute] Command returned: (code: 1, stdout: Error occurred during build: Command command01 failed
, stderr: None)
2014-02-03 12:54:25,533 [DEBUG] (1923 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: {'status': 'FAILURE', 'results': [{'status': 'FAILURE', 'config_sets': ['Infra-WriteRuntimeConfig', 'Infra-WriteApplication1', 'Infra-WriteApplication2', 'Infra-EmbeddedPreBuild', 'Hook-PreAppDeploy', 'Infra-EmbeddedPostBuild', 'Hook-EnactAppDeploy', 'Hook-PostAppDeploy'], 'returncode': 1, 'events': [], 'msg': 'Error occurred during build: Command command01 failed\n'}], 'api_version': '1.0'}

我对弹性豆茎或外壳没有任何经验,因此很容易出现语法错误,但老实说我不知道​​要查看

【问题讨论】:

    标签: php shell amazon-web-services amazon-elastic-beanstalk


    【解决方案1】:

    啊,但这就是为什么与.ebextentions 一起工作如此有趣!

    从您附加的日志中,我唯一能看到的是,实际上是您名为command01 的命令失败了。究竟什么出了问题通常是一个反复试验的谜。

    这正是恢复您在“printf()-debugging”中可能拥有的任何旧技能的地方。您从调用的脚本中回显的任何内容也将输出到同一个日志文件 (/var/log/cfn-init.log),让您了解正在发生的事情...

    但是,看看你的脚本,我猜 $PARAM1 是未定义的。尝试将其作为参数传递给 container_command 中的 shell 脚本,如下所示:

    container_commands:
        command01:
            command: "./.ebextensions/setEnvVars.sh" ${PARAM1}
    

    然后在你的 Bash case 语句中使用第一个参数:

    #!/bin/bash
    case "$1" in
        ...
    esac
    

    祝你好运!


    编辑:哦,还有一件事。您当然需要在 AWS 控制台中设置 PARAM1 参数。您可以在 Configuration > Software Configuration > Environment Properties 中执行此操作。以防万一您还没有这样做...

    【讨论】:

      【解决方案2】:

      调试脚本问题的一个有用技巧是将 stdout/stderr 重定向到文件。

      commands:
        command-00:
          command: my_command args >> commands.out 2&>1
      

      【讨论】:

        猜你喜欢
        • 2012-07-23
        • 2015-03-20
        • 2018-06-14
        • 2016-01-04
        • 2018-02-25
        • 2019-11-06
        • 2018-03-23
        • 2016-01-13
        • 2015-04-02
        相关资源
        最近更新 更多