Hic*_*ick 17 python django celery
我在这里的代码中创建了/ etc/defaults /中的celeryd文件:
https://github.com/celery/celery/blob/3.0/extra/generic-init.d/celeryd
现在当我想将celeryd作为一个守护进程运行并执行此操作时:sudo /etc/init.d/celerdy它说命令未找到.我哪里错了?
小智 19
我不确定你在这里做什么,但这些是将芹菜作为守护进程运行的步骤.
/etc/init.d
文件夹中,并带有名称
celeryd
/etc/default
,其名称 celeryd
由上述脚本使用.此配置文件基本上定义了上述脚本使用的某些变量和路径.这是一个示例配置.我发现这个链接非常有用:如何在virtualenv中为Celery(django-celery)编写Ubuntu Upstart作业
稍微调整一下..我有一个使用这个脚本运行的芹菜工人:
(使用ubuntu upstart)
命名为iamcelery.conf并将其放在/ etc/init中(注意:不是init.d)
# iamcelery -runs the celery worker as my virtual env user
#
#
# This task is run on startup to start the celery worker as my vritual env user
description "runs the celery worker"
author "michel van Leeuwen <michel@iamit.nl>"
start on runlevel [2345]
stop on runlevel [!2345]
# retry if ended unexpectedly
respawn
# limit the retries to max 15 times with timeouts of 5 seconds
respawn limit 15 5
# Time to wait between sending TERM and KILL signals
kill timeout 20
task
script
exec su -s /bin/sh -c 'exec "$0" "$@"' <place here your unprovilegd username> -- srv/<here the path of your django project>/bin/django celeryd -BE -l info
end script
Run Code Online (Sandbox Code Playgroud)
现在你可以开始这个scipt(它也在服务器启动时启动):
sudo start iamcelery
Run Code Online (Sandbox Code Playgroud)
或停止:
sudo stop iamcelery
Run Code Online (Sandbox Code Playgroud)
或检查其状态:
sudo status iamcelery
Run Code Online (Sandbox Code Playgroud)
我不确定这是最好的方式....但是......经过长时间的试验和错误试图让initd脚本工作....(没有成功)......这终于有效了.
编辑2013年6月8日 我在这里给出的脚本似乎最终以root身份运行.现在我改变了这个:
script
su <place here your unprovilegd username>
cd /srv/<here the path of your django project>/
exec bin/django celeryd -BE -l info
end script
Run Code Online (Sandbox Code Playgroud)
成:
script
exec su -s /bin/sh -c 'exec "$0" "$@"' <place here your unprovilegd username> -- srv/<here the path of your django project>/bin/django celeryd -BE -l info
end script
Run Code Online (Sandbox Code Playgroud)
这是有效的,这个问题的答案的所有功劳: 如何在virtualenv中为Celery(django-celery)编写Ubuntu Upstart工作
编辑2013年9月5日
剩下一件小事:我必须在控制台中的start命令之后执行ctrl-c(并在此之后执行状态检查):如果有人知道这一点:请保留命令,我可以更新此答案. ..
为此,我通常使用主管(加上django-supervisor).这样,你不需要弄清楚如何守护你的应用程序中的每个进程(你至少有一个托管django的网络服务器,加上芹菜,加上你用来支持这两者的其他中间件).主管知道如何将自己作为守护进程运行,并且所有其他进程都作为主管的子进程运行.