根据Amazon documentation for container_commands:
它们在应用程序和网络服务器设置完毕并提取应用程序版本文件之后运行,但在应用程序版本部署之前。
(强调我的)
这意味着此时您为命令设置为cwd 的/var/app/current 仍指向以前的版本。但是默认情况下,再次来自文档,cwd:
是解压后的应用目录。
这意味着如果您想从刚刚提取(但尚未部署)的应用程序的目录中运行delayed_job,请不要覆盖cwd,它应该为即将执行的应用程序启动delayed_job部署。
参考:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands
更新:
我现在自己进行了设置,发现通过标准 container_commands 执行此操作存在限制 - 基本上,delayed_job 将在它仍在 /var/app/ondeck 目录中时启动。通常这没问题,但我在某些工作中遇到了一些问题,因为该路径卡在它周围会导致错误,因为应用程序现在位于 /var/app/current。
我发现了一种未记录的(非常警告!)方法,您可以添加脚本以在您的应用服务器重新启动后运行(并且您的新部署位于 /var/app/current)。
基本上,Elastic Beanstalk 将在 Web 服务器重新启动后执行 /opt/elasticbeanstalk/hooks/appdeploy/post 中的任何脚本。这意味着如果您将 shell 脚本放在此目录中,它们将被运行。
我创建了一个这样的 shell 脚本:
#!/usr/bin/env bash
. /opt/elasticbeanstalk/support/envvars
cd $EB_CONFIG_APP_CURRENT
su -c "RAILS_ENV=production script/delayed_job --pid-dir=$EB_CONFIG_APP_SUPPORT/pids restart" $EB_CONFIG_APP_USER
我将此脚本上传到 S3 存储桶,并确保它是“公开的”。然后,您可以使用.ebextensions 目录中的选项脚本(例如99delayed_job.config)将此脚本部署为应用程序部署的一部分,注意post 目录可能不存在:
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh":
mode: "000755"
owner: root
group: root
source: http://YOUR_BUCKET.s3.amazonaws.com/99_restart_delayed_job.sh
部署时,您应该在/var/log/eb-tools.log 中看到类似的内容:
2013-05-16 01:20:53,759 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing directory: /opt/elasticbeanstalk/hooks/appdeploy/post/
2013-05-16 01:20:53,760 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh
2013-05-16 01:21:02,619 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: delayed_job: trying to stop process with pid 6139...
delayed_job: process with pid 6139 successfully stopped.
2013-05-16 01:21:02,620 [INFO] (6467 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded.
正如我所说,将内容放入此“post”目录是未记录的 - 但希望亚马逊在某个时候为 .options 脚本添加实际支持以在部署后运行命令,在这种情况下,您可以将其移至官方支持的方法。