2013-06-03 50 views
2

我试图daemonize在virtualenv内运行的django的芹菜过程。我从https://github.com/celery/celery/tree/master/extra/generic-init.d复制celeryd文件/etc/init.d/中daemonizing芹菜过程芹菜多没有找到

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

这是我的/ etc /默认/ 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

显示芹菜多可用。

[更新 - 修正与@Daniel罗斯曼的输入我起动命令]

现在,当我运行:

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=/path/to/project/

OK

+ sleep 5

+ exit 0

我在这里错过了什么?请帮忙!

回答

2

当您执行使用sudo sh命令,你开始一个全新的shell环境。在该环境中,您的virtualenv未激活,并且virtualenv的bin目录不在路径上,这可能是为什么找不到可执行文件。

如果你真的需要运行这个作为超级用户,您应该创建一个执行sudo调用内部的virtualenv包装脚本。

+0

非常感谢这个输入!我本人不会想到这一点。这应该让我更接近解决方案。 – manu

3

你的init.d脚本引用了系统python包,而不是virtualenv python。所以当你在里面运行芹菜时,你正在引用系统站点包中安装的那个。

调用芹菜之前添加到的virtualenv的python路径的引用,一切都应该工作得很好。

话虽这么说,它通常是更好地使用的init.d到supervisord运行,然后有supervisord旋转起来的所有其他进程如芹菜和Web应用程序。

+0

正如@丹尼尔罗斯曼所说的,我尝试了没有sudo盈余的命令。现在它似乎启动了一些节点,但后来在'ps aux |中看不到任何芹菜进程grep芹菜' – manu