栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用AWS Elastic Beanstalk运行工作程序?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用AWS Elastic Beanstalk运行工作程序?

正如@ chris-wheadon在其评论中建议的那样,你应该尝试在后台将Celery作为恶魔运行。AWS Elastic Beanstalk 已使用supervisor运行某些守护进程。因此,你可以利用它来运行celeryd并避免为此创建自定义AMI。它对我很好。

我要做的是在EB将应用程序部署到实例之后,以编程方式将celeryd配置文件添加到实例。棘手的部分是,该文件需要设置守护进程所需的环境变量(例如,如果你在应用程序中使用S3或其他服务,则需要使用AWS访问密钥)。

下面是我使用的脚本的副本,将此脚本添加到

.ebextensions
配置EB环境的文件夹中。

安装脚本会在文件

/opt/elasticbeanstalk/hooks/appdeploy/post/
夹(文档)中创建一个文件,该文件位于所有EB实例上。部署后将执行其中的任何shell脚本。放置在那里的shell脚本的工作方式如下:

  1. celeryenv
    变量中,virutalenv环境以遵循监督符号的格式存储。这是逗号分隔的env变量列表。
  2. 然后,脚本创建一个变量
    celeryconf
    ,该变量将配置文件包含为字符串,其中包括先前解析的env变量。
  3. 然后将此变量通过管道传递到
    celeryd.confcelery
    守护程序的受监管配置文件中。
  4. 最后,将新创建的配置文件的路径添加到主
    supervisord.con
    f文件(如果尚未存在)。
    这是脚本的副本:
files:  "/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh":    mode: "000755"    owner: root    group: root    content: |      #!/usr/bin/env bash      # Get django environment variables      celeryenv=`cat /opt/python/current/env | tr 'n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'`      celeryenv=${celeryenv%?}      # Create celery configuraiton script      celeryconf="[program:celeryd]      ; Set full path to celery program if using virtualenv      command=/opt/python/run/venv/bin/celery worker -A myappname --loglevel=INFO      directory=/opt/python/current/app      user=nobody      numprocs=1      stdout_logfile=/var/log/celery-worker.log      stderr_logfile=/var/log/celery-worker.log      autostart=true      autorestart=true      startsecs=10      ; Need to wait for currently executing tasks to finish at shutdown.      ; Increase this if you have very long running tasks.      stopwaitsecs = 600      ; When resorting to send SIGKILL to the program to terminate it      ; send SIGKILL to its whole process group instead,      ; taking care of its children as well.      killasgroup=true      ; if rabbitmq is supervised, set its priority higher      ; so it starts first      priority=998      environment=$celeryenv"      # Create the celery supervisord conf script      echo "$celeryconf" | tee /opt/python/etc/celery.conf      # Add configuration script to supervisord conf (if not there already)      if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf          then          echo "[include]" | tee -a /opt/python/etc/supervisord.conf          echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf      fi      # Reread the supervisord config      supervisorctl -c /opt/python/etc/supervisord.conf reread      # Update supervisord in cache without restarting all services      supervisorctl -c /opt/python/etc/supervisord.conf update      # Start/Restart celeryd through supervisord      supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/387838.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号