根据亚马逊文档container_commands
:
它们在应用程序和 Web 服务器已设置并且应用程序版本文件已提取,但在应用程序版本部署之前运行。
(强调我的)
这意味着在/var/app/current
您设置为cwd
for 您的命令的那一点仍然指向以前的版本。但是,默认情况下,再次从文档中cwd
:
是解压后的应用目录。
这意味着如果您想delayed_job
从刚刚提取(但尚未部署)的应用程序的目录运行,请不要覆盖cwd
,它应该为即将部署的应用程序启动延迟作业。
参考: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 将/opt/elasticbeanstalk/hooks/appdeploy/post
在 Web 服务器重新启动后执行任何脚本。这意味着如果您将 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
脚本添加实际支持以在部署后运行命令,在这种情况下,您可以将其移至官方支持的方法。