首页 > 解决方案 > 无法在 AWS ElasticBeanstalk 上运行后台工作程序

问题描述

我正在尝试将 ElasticBeanstalk 配置为在 Docker 容器内运行 Flask-RQ2 工作程序。因此,我在 .ebextensions 目录下创建了以下配置:

files:
    "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_workers.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #nohup docker exec $(docker ps | grep $(docker images -q aws_beanstalk/current-app) | awk '{print $1}') flask rq worker > /dev/null 2>&1 &

container_commands:
    001-run-worker:
    leader_only: true
    command: "sed -i -e 's/#//' /opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_workers.sh"
    ignoreErrors: true

部署后,它无法看到工作人员正在运行。

$ docker exec $(docker ps | grep $(docker images -q aws_beanstalk/current-app) | awk '{print $1}') flask rq info
default      | 0
1 queues, 0 jobs total

0 workers, 1 queues

Updated: 2019-01-31 19:44:13.182584

在 SSH 下调用 worker 命令效果很好:

$ docker exec $(docker ps | grep $(docker images -q aws_beanstalk/current-app) | awk '{print $1}') flask rq worker
[2019-01-31 19:46:04,618] INFO in worker: RQ worker 'rq:worker:72892ec44d9b.66' started, version 0.13.0
[2019-01-31 19:46:04,620] INFO in worker: *** Listening on default...
[2019-01-31 19:46:04,621] INFO in worker: Cleaning registries for queue: default

我究竟做错了什么?


UPD

今天重新部署了应用程序,工人似乎已启动。

$ docker exec $(docker ps | grep $(docker images -q aws_beanstalk/current-app) | awk '{print $1}') flask rq info
default      | 0
1 queues, 0 jobs total

f89e0061ba39.13 idle: default
1 workers, 1 queues

Updated: 2019-02-01 08:24:40.154956

标签: python-3.xdockerflaskamazon-elastic-beanstalk

解决方案


推荐阅读