AWS ElasticBeanstalk .ebextensions 未执行

Posted

技术标签:

【中文标题】AWS ElasticBeanstalk .ebextensions 未执行【英文标题】:AWS ElasticBeanstalk .ebextensions not being executed 【发布时间】:2017-05-24 03:22:53 【问题描述】:

我正在尝试在 AWS EB 上完成一些部署后的工作。我已将我的.ebextensions 添加到 git 存储库中,我只有一个文件01_container_commands.config,当我尾随/var/log/eb-activity.log 时它似乎没有运行在某一时刻它正在运行并且在下面列出的命令 05 上失败所以我删除了 05 但现在它根本不运行。

container_commands:
  01_user_permission:
    command: /usr/sbin/usermod -a -G webapp ec2-user
  02_remove_storage_directory:
    command: rm -rf /var/app/current/storage
  03_create_storage_directories:
    command: mkdir /var/app/current/storage /var/app/current/storage/framework /var/app/current/storage/framework/session /var/app/current/storage/framework/views /var/app/current/storage/framework/cache
  04_set_storage_permissions:
    command: chmod -fR 755 /var/app/current/storage
  05_copy_env_file
    command: cp /var/app/current/.aws.env /var/app/current/.env

它似乎没有运行我的 ebextensions,有什么想法可以检查以找出原因吗?

作为旁注,我尝试用双引号将命令括起来,但这似乎也没有帮助。

正如您在下面看到的,它根本没有执行我的脚本。

[2017-01-09T19:59:09.615Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/AppDeployPreHook/12_update_permissions.sh] : Starting activity...
[2017-01-09T19:59:20.431Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/AppDeployPreHook/12_update_permissions.sh] : Completed activity. Result:
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_user
  + EB_APP_USER=webapp
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_base_dir
  + EB_APP_BASE_DIR=/var/app
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
  + EB_APP_STAGING_DIR=/var/app/ondeck
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_logs_dir
  + EB_APP_LOGS_DIR=/var/app/support/logs
  + cd /var/app/ondeck
  + chown -R webapp:webapp /var/app
  + chown -R webapp:webapp /var/log/httpd
  + '[' -f app/SymfonyRequirements.php ']'
[2017-01-09T19:59:20.431Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/AppDeployPreHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2017-01-09T19:59:20.432Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/EbExtensionPostBuild] : Starting activity...
[2017-01-09T19:59:21.040Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2017-01-09T19:59:21.040Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Completed activity.
[2017-01-09T19:59:21.075Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/EbExtensionPostBuild] : Completed activity.
[2017-01-09T19:59:21.076Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/InfraCleanEbextension] : Starting activity...
[2017-01-09T19:59:21.157Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0/InfraCleanEbextension] : Completed activity. Result:
  Cleaned ebextensions subdirectories from /var/app/ondeck.
[2017-01-09T19:59:21.157Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage0] : Completed activity. Result:
  Application update - Command CMD-AppDeploy stage 0 completed
[2017-01-09T19:59:21.158Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1] : Starting activity...
[2017-01-09T19:59:21.158Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployEnactHook] : Starting activity...
[2017-01-09T19:59:21.158Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployEnactHook/01_flip.sh] : Starting activity...
[2017-01-09T19:59:21.535Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployEnactHook/01_flip.sh] : Completed activity. Result:
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
  + EB_APP_STAGING_DIR=/var/app/ondeck
  ++ /opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir
  + EB_APP_DEPLOY_DIR=/var/app/current
  + '[' -d /var/app/current ']'
  + mv /var/app/current /var/app/current.old
  + mv /var/app/ondeck /var/app/current
  + nohup rm -rf /var/app/current.old
[2017-01-09T19:59:21.535Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployEnactHook/99_reload_app_server.sh] : Starting activity...
[2017-01-09T19:59:21.677Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployEnactHook/99_reload_app_server.sh] : Completed activity. Result:
  Equivalent Upstart operations: start httpd, stop httpd, restart httpd, status httpd
  Gracefully restarting httpd
  [OK]
[2017-01-09T19:59:21.677Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployEnactHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/enact.
[2017-01-09T19:59:21.678Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployPostHook] : Starting activity...
[2017-01-09T19:59:21.678Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployPostHook/01_monitor_httpd_pid.sh] : Starting activity...
[2017-01-09T19:59:22.168Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployPostHook/01_monitor_httpd_pid.sh] : Completed activity. Result:
  + chmod 0755 /var/run/httpd
  + /opt/elasticbeanstalk/bin/healthd-track-pidfile --proxy httpd
[2017-01-09T19:59:22.168Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1/AppDeployPostHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/post.
[2017-01-09T19:59:22.169Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AppDeployStage1] : Completed activity. Result:
  Application version switch - Command CMD-AppDeploy stage 1 completed
[2017-01-09T19:59:22.169Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter] : Starting activity...
[2017-01-09T19:59:22.169Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigLogRotation] : Starting activity...
[2017-01-09T19:59:22.170Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigLogRotation/10-config.sh] : Starting activity...
[2017-01-09T19:59:22.611Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigLogRotation/10-config.sh] :     Completed activity. Result:
  Disabled forced hourly log rotation.
[2017-01-09T19:59:22.612Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigLogRotation] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/addons/logpublish/hooks/config.
[2017-01-09T19:59:22.612Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigCWLAgent] : Starting activity...
[2017-01-09T19:59:22.613Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigCWLAgent/10-config.sh] : Starting activity...
[2017-01-09T19:59:22.923Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigCWLAgent/10-config.sh] : Completed activity. Result:
  Log streaming option setting is not specified, ignore cloudwatch logs setup.

  Disabled log streaming.
[2017-01-09T19:59:22.923Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter/ConfigCWLAgent] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/addons/logstreaming/hooks/config.
[2017-01-09T19:59:22.923Z] INFO  [26612] - [Application update app-fb58-170109_145741@53/AddonsAfter] : Completed activity.
[2017-01-09T19:59:22.924Z] INFO  [26612] - [Application update app-fb58-170109_145741@53] : Completed activity. Result:
  Application update - Command CMD-AppDeploy succeeded

【问题讨论】:

您如何将其部署到 EB? 我正在使用 CLI 工具 eb deploy,部署工作正常,但是配置文件只是有时执行,而不是每次部署时都执行。最近,它似乎刚刚停止一起执行。 【参考方案1】:

根据the documentation,您的命令应该用双引号引起来,如下所示。 05_copy_env_file 后面也少了一个冒号。

我知道您说您尝试过双引号,但是您可以在修复引号和冒号后重试吗?另外,请使用您的新 01_container_commands.config 文件和整个 /var/log/eb-activity.log 文件更新您的问题。谢谢!

container_commands:
  01_user_permission:
    command: "/usr/sbin/usermod -a -G webapp ec2-user"
  02_remove_storage_directory:
    command: "rm -rf /var/app/current/storage"
  03_create_storage_directories:
    command: "mkdir /var/app/current/storage /var/app/current/storage/framework /var/app/current/storage/framework/session /var/app/current/storage/framework/views /var/app/current/storage/framework/cache"
  04_set_storage_permissions:
    command: "chmod -fR 755 /var/app/current/storage"
  05_copy_env_file:
    command: "cp /var/app/current/.aws.env /var/app/current/.env"

【讨论】:

我试过带引号和不带引号。这不是问题,即使在修复了那些它也不起作用。原因是因为我需要在没有真正记录的“部署后”做这些事情,这篇文章让事情开始为我工作。 junkheap.net/blog/2013/05/20/… 很高兴听到您成功了!我希望 AWS 能够正式支持“部署后”技术,但正如您发现的那样,它工作得很好。话虽这么说,你的01_user_permission 步骤应该像普通的container_command 一样运行,因为它不会影响/var/app/current

以上是关于AWS ElasticBeanstalk .ebextensions 未执行的主要内容,如果未能解决你的问题,请参考以下文章

强制 https aws elasticbeanstalk

从在 ElasticBeanstalk 中运行的 Flask 应用程序使用 AWS

在 AWS 上使用 ElastiCache 和 ElasticBeanstalk 配置 Redis

是否有任何东西可以将 AWS::ElasticBeanstalk::Environment 链接到它创建的嵌套堆栈?

Rails 部署到 AWS ElasticBeanstalk/RDS 失败

AWS Elasticbeanstalk 部署错误