加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何在Amazon Elastic Beanstalk上部署rails项

发布时间:2020-12-16 20:08:46 所属栏目:百科 来源:网络整理
导读:我在 Amazon Elastic Beanstalk上安装了一个rails项目,我尝试配置一个 container command,以便在每次部署后自动重新启动服务器上的 delayed_job worker. 我试过这个: container_commands: restartdelayedjob: command: "RAILS_ENV=production script/delaye
我在 Amazon Elastic Beanstalk上安装了一个rails项目,我尝试配置一个 container command,以便在每次部署后自动重新启动服务器上的 delayed_job worker.

我试过这个:

container_commands:
  restartdelayedjob:
    command: "RAILS_ENV=production script/delayed_job --pid-dir=/home/ec2-user/pids start"
    cwd: /var/app/current

但是,似乎在重新启动worker之后部署了推送版本,因此工作无法由工作人员处理.

当我通过ssh连接我的实例时,从部署的版本文件夹中删除工作进程并重新启动一个新的进程,一切正常.

你有什么想法可以解决这个问题吗?

谢谢

解决方法

根据 Amazon documentation for container_commands

They run after the application and web server have been set up and the application version file has been extracted,but before the application version is deployed.

(强调我的)

这意味着在那个/ var / app / current你正在设置为您的命令的cwd仍然指向以前的版本.但是默认情况下,从文档再次,cwd:

is the directory of the unzipped application.

这意味着如果要从刚刚解压缩的应用程序的目录(但尚未部署)运行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中).

基本上弹性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脚本中添加实际的支持来运行命令后部署,在这种情况下,你可以把它移到官方支持的方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读