【发布时间】:2016-05-21 13:10:24
【问题描述】:
我正在尝试使用 celery 和 redis 队列为我的 Django 应用程序执行任务。 Supervisord 通过apt-get 安装在主机上,而 celery 位于我系统上的特定 virtualenv 中,通过 `pip.
因此,我似乎无法通过 supervisord 运行 celery 命令。如果我从 virtualenv 内部运行它,它可以正常工作,在它之外,它不会。如何让它在我当前的设置下运行?解决方案是否只是通过 apt-get 安装celery,而不是在 virtualenv 中?请指教。
我在 /etc/supervisor/conf.d 里面的 celery.conf 是:
[program:celery]
command=/home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/celery/bin/celery -A /etc/supervisor/conf.d/celery.conf -l info
directory = /home/mhb11/somefolder/myproject
environment=PATH="/home/mhb11/.virtualenvs/myenv/bin",VIRTUAL_ENV="/home/mhb11/.virtualenvs/myenv",PYTHONPATH="/home/mhb11/.virtualenvs/myenv/lib/python2.7:/home/mhb11/.virtualenvs/myenv/lib/python2.7/site-packages"
user=mhb11
numprocs=1
stdout_logfile = /etc/supervisor/logs/celery-worker.log
stderr_logfile = /etc/supervisor/logs/celery-worker.log
autostart = true
autorestart = true
startsecs=10
stopwaitsecs = 600
killasgroup = true
priority = 998
我的 Django 项目的文件夹结构是:
/home/mhb11/somefolder/myproject
├── myproject
│ ├── celery.py # The Celery app file
│ ├── __init__.py # The project module file (modified)
│ ├── settings.py # Including Celery settings
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── celerybeat-schedule
└── myapp
├── __init__.py
├── models.py
├── tasks.py # File containing tasks for this app
├── tests.py
└── views.py
如果我通过 supervisorctl 进行status 检查,我会在尝试在 celery.conf 中运行的command 上收到致命错误。救命!
附言请注意,用户 mhb11 没有 root 权限,以防万一。此外,/etc/supervisor/logs/celery-worker.log 是空的。在supervisord.log 内部,我看到的相关错误是INFO spawnerr: can't find command '/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/celery/bin/celery'。
【问题讨论】:
-
从终端运行
/home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/celery/bin/celery -A /etc/supervisor/conf.d/celery.conf -l info会发生什么? -
/etc/supervisor/logs/celery-worker.log有什么?/var/log/supervisord.log或/var/log/supervisor/supervisord.log有什么作用? -
@MuhammadTahir:
/etc/supervisor/logs/celery-worker.log为空。在supervisord.log内部,我看到的相关错误是INFO spawnerr: can't find command '/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/celery/bin/celery'。 -
@MuhammadTahir:如果我尝试运行
/home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/celery/bin/celery -A /etc/supervisor/conf.d/celery.conf -l info,我会得到-bash: /home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/celery/bin/celery: No such file or directory
标签: python django redis celery supervisord