让 django 芹菜工人开始使用 elastic-beanstalk 的问题

Issue getting django celery worker started on elastic-beanstalk

我正在尝试让我的 celery worker 运行 使用 elastic-beanstalk。它在本地运行良好,但是当我部署到 EB 时,出现错误 "Activity execution failed, because: /usr/bin/env: bash":没有这样的文件或目录”。我在 celery 和 EB 方面还是个新手,所以到目前为止我还没有找到解决方案。

我在 windows 机器上工作,我看到其他人遇到这个问题 windows 并通过将 "celery_configuration.txt" 文件转换为 UNIX EOL 来修复它,但是我正在使用celery-worker.sh 而不是,但我将其转换为 UNIX EOL,但仍然无法正常工作。

.ebextensions/celery.config

packages:
  yum:
    libcurl-devel: []

container_commands:
    01_mkdir_for_log_and_pid:
        command: "mkdir -p /var/log/celery/ /var/run/celery/"
    02_celery_configure:
        command: "cp .ebextensions/celery-worker.sh /opt/elasticbeanstalk/hooks/appdeploy/post/ && chmod 744 /opt/elasticbeanstalk/hooks/appdeploy/post/celery-worker.sh"
        cwd: "/opt/python/ondeck/app"
    03_celery_run:
        command: "/opt/elasticbeanstalk/hooks/appdeploy/post/celery-worker.sh"

.ebextensions/celery-worker.sh

#!/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-worker]
; Set full path to celery program if using virtualenv
command=/opt/python/run/venv/bin/celery worker -A backend -P solo --loglevel=INFO -n worker.%%h

directory=/opt/python/current/app/enq_web
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
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf reread

# Update supervisord in cache without restarting all services
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf update

# Start/Restart celeryd through supervisord
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd-worker

我确定我错过了一些简单的事情,但我花了几个小时到处寻找解决方案,此时我已经没有主意了。

问题出在您的 celery-worker.sh 文件中的 shebang(#!/usr/bin/env bash)行,请尝试使用 /bin/bash/bin/sh。 bash 或 sh live 的位置在很大程度上取决于您使用 beantalk 的 AMI。