【问题标题】:uwsgi error: "celery: not found" with celery run in a venv with attach-daemon2uwsgi 错误:“芹菜:未找到”,芹菜在带有 attach-daemon2 的 venv 中运行
【发布时间】:2019-06-27 17:27:19
【问题描述】:

如果我在我的 django 应用程序的虚拟环境中手动运行 celery,它可以工作:

(hackerspace) 90158@hackerspace:~/hackerspace/src$ celery -A hackerspace_online worker -l info -c 3 -Q default

 -------------- celery@hackerspace v4.3.0 (rhubarb)
---- **** ----- 
--- * ***  * -- Linux-4.4.0-151-generic-x86_64-with-Ubuntu-16.04-xenial 2019-06-27 10:19:53
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         hackerspace_online:0x7f8ecb7dbba8
- ** ---------- .> transport:   redis://127.0.0.1:6379/0
- ** ---------- .> results:     
- *** --- * --- .> concurrency: 3 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> default          exchange=default(direct) key=default


[tasks]
  . hackerspace_online.celery.debug_task
  . update_conditions_for_quest
  . update_quest_conditions_all
  . update_quest_conditions_for_user

[2019-06-27 10:19:53,439: INFO/MainProcess] Connected to redis://127.0.0.1:6379/0
[2019-06-27 10:19:53,447: INFO/MainProcess] mingle: searching for neighbors
[2019-06-27 10:19:54,466: INFO/MainProcess] mingle: all alone
[2019-06-27 10:19:54,482: INFO/MainProcess] celery@hackerspace ready.

但我无法让它与 uwsgi 的 attach-daemon2 一起运行:

#hackerspace_uwsgi.ini
[uwsgi]
...
attach-daemon2  = cmd=%(chdir)/celery -A hackerspace_online worker -l info -c 3 -Q default

我的 uwsgi 日志给了我这个错误:

[uwsgi-daemons] respawning "/home/90158/hackerspace/src/celery -A hackerspace_online worker -l info -c 3 -Q default" (uid: 33 gid: 33)
/bin/sh: 1: /home/90158/hackerspace/src/celery: not found

这似乎表明它不是在虚拟环境中运行的。如何让 uwsgi 运行 celery,使其像手动运行时一样工作?

【问题讨论】:

    标签: celery virtualenv uwsgi django-celery


    【解决方案1】:

    uwsgi docs 说要尝试使用smart-attach-daemon 和 pidfile。 celery 本身推荐使用multi to start workers when daemonizing:

    [uwsgi]
    master = true
    socket = :3031
    smart-attach-daemon = /tmp/celery.pid celery -A tasks worker --pidfile=/tmp/celery.pid
    

    【讨论】:

      【解决方案2】:

      我发现的最好方法

      attach-daemon = bash -c "cd /var/www/application/ ; source /srv/nopow_link/bin/activate && celery -A main worker --loglevel=info -f /var/log/uwsgi/app/celery.log"
      

      要登录,请确保 www-data 或 uwsgi 使用的用户具有写入权限。

      chown www-data:www-data /var/log/uwsgi/app/celery.log
      chmod 644 /var/log/uwsgi/app/celery.log
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-18
        相关资源
        最近更新 更多