【问题标题】:Errors adding Environment Variables to NodeJS Elastic Beanstalk将环境变量添加到 NodeJS Elastic Beanstalk 时出错
【发布时间】:2018-07-29 00:16:54
【问题描述】:

我的配置一直运行到昨天。我添加了nginx NodeJS https redirect extension from AWS。现在,当我尝试通过 Elastic Beanstalk 配置添加新环境变量时,我收到此错误:

[Instance: i-0364b59cca36774a0] Command failed on instance. Return code: 137 Output: + rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf + service nginx stop Stopping nginx: /sbin/service: line 66: 27395 Killed env -i PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS}. Hook /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

当我查看 eb-activity.log 时,我看到了这个错误:

[2018-02-18T17:24:58.762Z] INFO  [13848] - [Configuration update 1.0.61@112/ConfigDeployStage1/ConfigDeployPostHook/99_kill_default_nginx.sh] : Starting activity...
[2018-02-18T17:24:58.939Z] INFO  [13848] - [Configuration update 1.0.61@112/ConfigDeployStage1/ConfigDeployPostHook/99_kill_default_nginx.sh] : Activity execution failed, because: + rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
  + service nginx stop
  Stopping nginx: /sbin/service: line 66: 14258 Killed                  env -i PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS} (ElasticBeanstalk::ExternalInvocationError)
caused by: + rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
  + service nginx stop
  Stopping nginx: /sbin/service: line 66: 14258 Killed                  env -i PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" ${OPTIONS} (Executor::NonZeroExitStatus)

我做错了什么?最近发生了什么变化,因为几个月前我更改了环境变量时效果很好。

【问题讨论】:

  • 你最后解决了这个问题吗?我面临类似的事情,我只是使用文档中指定的配置
  • 不。我可以解决它的唯一方法是在没有 00_elastic_beanstalk_proxy.conf 的情况下推送新负载,重建环境,更改变量,然后将所有内容(00_elastic_beanstalk_proxy.conf)放回去。

标签: amazon-web-services nginx amazon-elastic-beanstalk


【解决方案1】:

在我看来,事件的顺序是这样的:

  1. 创建部署后挂钩以删除/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
  2. 运行容器命令删除/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
  3. 运行部署后挂钩,它会尝试删除/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf

因此,部署后脚本失败,因为您尝试删除的文件可能不存在,这对我来说似乎并不奇怪。

我会尝试以下两种方法之一:

  1. 将临时 conf 文件的删除从容器命令移至 99_kill_default_nginx.sh 脚本,然后删除整个容器命令部分。
  2. 99_kill_default_nginx.sh 脚本中删除rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf 行。

【讨论】:

  • 嗯。我都尝试了,但仍然失败。上传新代码后,任何配置(包括原始配置)和一切都很好。但是,如果我对配置进行任何更改,更改将失败并返回到以前的配置。
【解决方案2】:

我也遇到了这个问题,亚马逊在文档中承认了这个错误。这是一个可以在 .ebextensions 配置文件中使用的有效重启脚本。

  /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash -xe
      rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
      status=`/sbin/status nginx`

      if [[ $status = *"start/running"* ]]; then
        echo "stopping nginx..."
        stop nginx
        echo "starting nginx..."
        start nginx
      else
        echo "nginx is not running... starting it..."
        start nginx
      fi

【讨论】:

    【解决方案3】:

    service nginx stop 退出,状态为 137(已杀死)。

    您的脚本开头为:#!/bin/bash -xe

    参数-e 使脚本在以非零状态退出时立即退出。 如果要继续执行,需要捕获退出状态(137)。

    /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
        mode: "000755"
        owner: root
        group: root
        content: |
          #!/bin/bash -xe
          rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
          status=`/sbin/status nginx`
          if [[ $status = *"start/running"* ]]; then
            set +e
            service nginx stop
            exitStatus = $?
            if [ $exitStatus -ne 0 ] && [ $exitStatus -ne 137 ]
            then
              exit $exitStatus
            fi
            set -e
          fi
          service nginx start
    

    【讨论】:

      【解决方案4】:

      /sbin/status nginx 似乎不再工作了。我更新了脚本以使用service nginx status

        /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
          mode: "000755"
          owner: root
          group: root
          content: |
            #!/bin/bash -xe
            rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
            status=$(service nginx status)
      
            if [[ "$status" =~ "running" ]]; then
              echo "stopping nginx..."
              stop nginx
              echo "starting nginx..."
              start nginx
            else
              echo "nginx is not running... starting it..."
              start nginx
            fi
      

      亚马逊文档中的错误脚本仍然存在……我想知道他们什么时候会修复它。时间已经够了

      【讨论】:

        猜你喜欢
        • 2016-08-17
        • 2014-08-07
        • 2015-08-05
        • 2020-11-09
        • 2017-07-24
        • 2015-06-08
        • 2017-04-07
        • 2020-09-15
        • 2015-04-02
        相关资源
        最近更新 更多