【问题标题】:daemonizing celery process celeryd-multi not found未找到守护 celery 进程 celeryd-multi
【发布时间】:2013-05-29 14:25:06
【问题描述】:

我正在尝试为在 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: 未找到

我可以看到它无法找到 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=celery --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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    话虽如此,通常最好使用 init.d 运行 supervisord,然后让 supervisord 启动所有其他进程,例如 celery 和 Web 应用程序。

    【讨论】:

    • 正如@Daniel Roseman 所说,我尝试在命令前不使用 sudo。现在它似乎正在启动一些节点,但是我在 ps aux | grep celery 中看不到任何 celery 进程
    【解决方案2】:

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

    如果您确实需要以超级用户身份运行它,您应该创建一个包装脚本,在 sudo 调用中执行 virtualenv。

    【讨论】:

    • 非常感谢您的意见!我自己不会想到这一点。这应该让我更接近解决方案。