部署在Amazon Elastic魔豆Rails项目时,如何自动重新启动的delayed_job? [英] How to automatically restart delayed_job when deploying a rails project on Amazon Elastic Beanstalk?

查看:165
本文介绍了部署在Amazon Elastic魔豆Rails项目时,如何自动重新启动的delayed_job?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主持的亚马逊弹性魔豆 Rails项目,我尝试配置<一href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands">container命令的自动重新启动我的的delayed_job 工人每个部署在服务器上。

I'm hosting a rails project on Amazon Elastic Beanstalk and I try to configure a container command to automatically restart my delayed_job worker on the server after each deployment.

我试着用这一个:

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

但是,似乎该推版本被工人的重新启动后部署这样的作业未能由工人进行处理。

But, it seems that the pushed version is deployed after the restarting of the worker so the jobs failed to be processed by the worker.

当我连接上我的实例通过SSH,杀了工作进程,并重新启动从部署的版本文件夹一个新的,一切工作正常。

When I connect on my instance by ssh, kill the worker process and restart a new one from the deployed version folder, everything works fine.

你有我怎么能处理这个任何想法?

Do you have any ideas of how I can handle this?

感谢

推荐答案

由于每<一href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands">Amazon为 container_commands文档

他们后运行应用程序和Web服务器已经设置和应用程序版本的文件已被提取,但应用程序版本部署之前

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 /应用/电流要为其设置为 CWD 为您的命令仍然是指向previous版本。但是在默认情况下,从文档再次, CWD

This means at that point /var/app/current which you are setting as the cwd for your command is still pointing to the previous version. However by default, from the docs again, cwd:

是解压缩后的应用程序的目录。

is the directory of the unzipped application.

这意味着,如果你想从刚刚提取的(但尚未部署的)应用程序的目录中运行的delayed_job ,不会覆盖 CWD ,它应该启动的delayed_job的应用程序,是即将被部署。

This means that if you want to run delayed_job from the directory of the app that just got extracted (but not yet deployed), don't override cwd and it should start the delayed_job for the app that's about to be deployed.

编号:<一href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands">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 /应用/电流

I've now set this up myself and found there's limitations to doing it via the standard container_commands - basically delayed_job will be started while it is still in the /var/app/ondeck directory. Usually this is OK, but I had some issues with some jobs because that path had stuck around it would cause errors as the app was now in /var/app/current.

我发现要运行,你可以添加脚本一个未公开的(所以警告!)方法之后,你的应用服务器重新启动(和你的新部署是的/ var /应用/电流)。

I found an undocumented (so warning!) approach that you can add scripts to be run AFTER your app server is restarted (and your new deploy is in /var/app/current).

基本上弹性魔豆将在的/ opt / elasticbeanstalk /钩/ appdeploy /后执行任何脚本

Basically Elastic Beanstalk will execute any scripts in /opt/elasticbeanstalk/hooks/appdeploy/post after the web server is restarted. This means if you drop shell scripts in this directory they will be run.

我创建了一个shell脚本是这样的:

I created a shell script like this:

#!/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 )来部署此脚本您的应用程序部署的一部分,注意到了目录可能不存在:

I uploaded this script to an S3 bucket, and made sure it was "public". You can then use an options script in your .ebextensions directory (eg. 99delayed_job.config) to deploy this script as part of your app deploy, taking note that the post directory might not exist:

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

When you deploy you should see something like this in your /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.

正如我所说的,把东西在这个后目录是未公开的 - 但我希望在某个时候亚马逊增加实际的支持,以可供选项脚本运行命令后部署,在这种情况下,你可以将这个对官方支持的做法。

As I said, putting stuff in this "post" directory is undocumented - but hopefully at some point Amazon add actual support to the .options scripts to run commands post-deploy, in that case you could move this to the officially supported approach.

这篇关于部署在Amazon Elastic魔豆Rails项目时,如何自动重新启动的delayed_job?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆