Elastic Beanstalk:我将如何仅在工作层上运行ebextension命令? [英] Elastic Beanstalk: How would I run an ebextension command on the worker tier only?

查看:62
本文介绍了Elastic Beanstalk:我将如何仅在工作层上运行ebextension命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹性的beantalk应用程序,它同时利用了Web层和辅助层.作业通过SQS从Web层转移到工作层上,以保持面向Web的服务器的速度.两种环境使用完全相同的代码库,并在其下使用RDS实例.

I have an elastic beanstalk application that utilises both the web tier and the worker tier. Jobs are offloaded onto the worker tier from the web tier via SQS to keep the web-facing servers speedy. Both environments use the exact same codebase, and use an RDS instance under them.

我需要在工作层的领导服务器上运行cron作业.我创建了一个.ebextensions文件夹,其中包含一个名为crontab的文件,如下所示(这是一个Laravel Web应用程序):

I need to run a cron job on the leader server of the worker tier. I've created a .ebextensions folder with a file called crontab in it as follows (it's a Laravel web app):

* * * * * root php /var/www/html/artisan do:something:with:database

然后,我创建了一个名为01cronjobs.config的文件,该文件将根目录下的crontab环境更新如下:

Then, I've created a file called 01cronjobs.config, which updates the environments crontab under root as follows:

container_commands:
  01_remove_old_cron_jobs:
  command: "crontab -r || exit 0"
  02_cronjobs:
  command: "cat .ebextensions/crontab | crontab"
  leader_only: true

..一切都很好.现在,我想使用eb deploy命令将其部署到EB.但是,我只希望工作者层可以执行cron作业,因为我们只能让一台服务器在整个组中运行cron.

.. all good. Now, I want to deploy this to EB using the eb deploy command. However, I only want the worker tier to take on the cron job, as we can only have one server run the crons throughout the group.

有没有办法让ebextensions配置文件仅在工作层上运行 ?像worker_only: true这样的东西在这里会很棒,但似乎不存在.

Is there a way to tell the ebextensions config file to only run the config command on the worker tier? Something like worker_only: true would be great here, but it doesn't seem to exist.

有人能提供一些有关我如何实现这一目标的见解吗?谢谢.

Can anybody provide some insight on how I might achieve this? Thanks.

推荐答案

  • 设置一个环境属性,例如"tier = worker". Elastic Beanstalk->应用程序->环境->配置->软件配置.
  • 使用命令"键的测试"属性测试该属性,因此仅在设置了环境属性时才执行命令.
  • AWS文档中的示例:

    Sample from the AWS doc:

    http://docs.aws.amazon. com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

    commands:
      python_install: 
        command: myscript.py
        cwd: /home/ec2-user
        env: 
          myvarname: myvarvalue
        test: '[ ! /usr/bin/python ] && echo "python not installed"'
    

    这篇关于Elastic Beanstalk:我将如何仅在工作层上运行ebextension命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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