daemonizing芹菜过程celeryd-multi未找到

时间:2013-06-03 12:26:58

标签: django deployment celery django-celery init.d

我正在尝试守护在virtualenv中运行的django的芹菜过程。我将celeryd文件从https://github.com/celery/celery/tree/master/extra/generic-init.d复制到了/etc/init.d /

然后我创建了一个包含http://ask.github.io/celery/cookbook/daemonizing.html#example-django-configuration-using-virtualenv内容的配置文件,并将其保存为/ etc / default / celeryd

这是我的/ etc / default / celeryd:

# Name of nodes to start, here we have a single node
CELERYD_NODES="w1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"

# Where to chdir at start.
CELERYD_CHDIR="/home/manu/location/to/project/"

# Python interpreter from environment.
ENV_PYTHON="/home/manu/.virtualenvs/project_env/bin/python"

# How to call "manage.py celeryd_multi"
CELERYD_MULTI= "$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryd_multi"

# How to call "manage.py celeryctl"
CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"

# Extra arguments to celeryd
CELERYD_OPTS="--verbose --fake --time-limit=300 --concurrency=8"

# Name of the celery config module.
CELERY_CONFIG_MODULE="celeryconfig"

# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Workers should run as an unprivileged user.
CELERYD_USER="celery"
CELERYD_GROUP="celery"

# Name of the projects settings module.
export DJANGO_SETTINGS_MODULE="project.settings.production"

当我跑步时:

sudo sh -x /etc/init.d/celeryd start

失败并出现以下错误:

  

celeryd-multi start w1 --uid = celery --gid = celery --workdir = / home / manu / location / to / project / --pidfile = / var / run / celery /%n.pid - logfile = / var / log / celery /%n.log --loglevel = INFO --cmd = -m celery.bin.celeryd_detach --verbose --fake --time-limit = 300 --concurrency = 8 / etc / init.d / celeryd:140:/etc/init.d/celeryd:celeryd-multi:not found

我可以看到它无法找到celeryd_multi。奇怪的是,正在运行

  

/ path / to / project_env / bin / python /path/to/manage.py celeryd_multi

显示celeryd-multi可用。

[更新 - 使用@Daniel Roseman的输入更正我的开始命令]

现在,当我跑:

sh -x /etc/init.d/celeryd start

这是我看到的输出:

  

/path/to/.virtualenvs/virtenv/bin/python/path/to/project//manage.py   celeryd_detach --time-limit = 300 --concurrency = 8 --gid =芹菜   --broker = AMQP://:@localhost:5672 //   -n w1.ubuntu-12-10 --logfile = / var / log / celery / w1.log --loglevel = INFO --uid = celery --pidfile = / var / run / celery / w1.pid --workdir = /路径/到/项目/

     

     

+睡5

     

+退出0

我在这里缺少什么?请帮忙!

2 个答案:

答案 0 :(得分:3)

你的init.d脚本引用了系统python包,而不是virtualenv python。因此,当您在其中运行芹菜时,您将引用系统站点包中安装的芹菜。

在调用celery之前添加对virtualenv python路径的引用,一切都应该正常工作。

话虽这么说,通常最好使用init.d运行supervisord,然后让supervisord启动所有其他进程,如celery和你的web应用程序。

答案 1 :(得分:2)

使用sudo sh执行命令时,您将启动一个全新的shell环境。在该环境中,您的virtualenv未被激活,并且virtualenv的bin目录将不在路径上,这可能是找不到可执行文件的原因。

如果你真的需要以超级用户身份运行它,你应该创建一个包装脚本来执行sudo调用中的virtualenv。