Issue with AWS Beanstalk command

2019-05-25 19:35发布

问题:

I've been using EBS without any problems. Today, I've added load balancer, and uploaded my package with the following configuration:

files:
  "/etc/nginx/conf.d/proxy.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


container_commands:
  01_reload_nginx:
    command: "service nginx reload"

However, when I am trying to launch the package, I get the following error:

Application deployment failed at 2016-11-23T14:07:40Z with exit status 7 and error: container_command 01_reload_nginx in .ebextensions/environment.config failed.

Whats going on?

These are the logs:

[eb-cfn-init]: Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre. [eb-cfn-init]: [2016-11-23T16:09:31.193Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild] : Starting activity... [eb-cfn-init]: [2016-11-23T16:09:31.506Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity... [eb-cfn-init]: [2016-11-23T16:09:31.507Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_My_First_Elastic_Beanstalk_Application] : Starting activity... [eb-cfn-init]: [2016-11-23T16:09:31.842Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_My_First_Elastic_Beanstalk_Application/Command 01_reload_nginx] : Starting activity... [eb-cfn-init]: [2016-11-23T16:09:31.868Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_My_First_Elastic_Beanstalk_Application/Command 01_reload_nginx] : Activity execution failed, because: (ElasticBeanstalk::ExternalInvocationError) [eb-cfn-init]: [eb-cfn-init]: [eb-cfn-init]: [2016-11-23T16:09:31.868Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_My_First_Elastic_Beanstalk_Application/Command 01_reload_nginx] : Activity failed. [eb-cfn-init]: [2016-11-23T16:09:31.868Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_My_First_Elastic_Beanstalk_Application] : Activity failed. [eb-cfn-init]: [2016-11-23T16:09:31.868Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Activity failed. [eb-cfn-init]: [2016-11-23T16:09:31.884Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0/EbExtensionPostBuild] : Activity failed. [eb-cfn-init]: [2016-11-23T16:09:31.884Z] INFO [2680] - [Application deployment ttttttt@4/StartupStage0] : Activity failed. [eb-cfn-init]: [2016-11-23T16:09:31.884Z] INFO [2680] - [Application deployment ttttttt@4] : Completed activity. Result: [eb-cfn-init]: Application deployment - Command CMD-SelfStartup failed

回答1:

Quite possibly your NGINX configuration file is broken and doesn't pass the test when NGINX reloads. During service reload, NGINX first checks your configuration file, if configuration is correct a HUP signal is sent to the NGINX process which gracefully shuts down old workers and starts new ones with the new configuration.

In order to verify your configuration file you can use below command:

/usr/bin/nginx -t -c ~/mynginx.conf

-t = Don’t run, just test the configuration file. NGINX checks configuration for correct syntax and then try to open files referred in configuration.

-c filename = your configuration file location (if not default)

You should be able to test your config with below command also (depending on what operating system you are on):

service nginx configtest

The first variation is preferable as it will also print any info, warning as well as error messages in your NGINX configuration.

Hope this helps.



回答2:

This is interesting because our elastic beanstalk deployment also failed yesterday on .ebextensions. It worked an hour later...

AWS deployed a new version of EB and S3 around the same time... https://aws.amazon.com/releasenotes/6845489088399156 https://aws.amazon.com/releasenotes/8532186109690530

I wonder if AWS is at fault?



回答3:

I had exactly the same issue, happening during platform upgrades. I contacted AWS support about this: they said they couldn't reproduce but had a very interesting piece of information which actually prevents this situation.

However, [command: "sudo service nginx reload"] is not necessary as nginx service restarts automatically after every successful deployment.

So you can just remove the

container_commands:
  01_reload_nginx:
    command: "service nginx reload"

part of the script so you'll never have the reload failure.