如何在生产中将芹菜作为守护进程运行?

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

我不确定你在这里做什么,但这些是将芹菜作为守护进程运行的步骤.

  1. 您在链接https://github.com/celery/celery/blob/3.0/extra/generic-init.d/celeryd中引用的文件 需要复制到您的/etc/init.d文件夹中,并带有名称 celeryd
  2. 然后,您需要在文件夹中创建一个配置文件 /etc/default,其名称 celeryd由上述脚本使用.此配置文件基本上定义了上述脚本使用的某些变量和路径.这是一个示例配置.
  3. 此链接Generic init脚本解释了该过程,可用于参考

  • 如果您阅读celery页面上的说明,也就不足为奇了,因为这意味着只有一个文件,并且它位于/ etc / default中。对于具有服务器端linux经验的人来说,可以解决问题,但是任何新手都会迷路。发布的答案应该在说明中 (2认同)

mic*_*mit 9

我发现这个链接非常有用:如何在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(并在此之后执行状态检查):如果有人知道这一点:请保留命令,我可以更新此答案. ..


Mar*_*cin 8

为此,我通常使用主管(加上django-supervisor).这样,你不需要弄清楚如何守护你的应用程序中的每个进程(你至少有一个托管django的网络服务器,加上芹菜,加上你用来支持这两者的其他中间件).主管知道如何将自己作为守护进程运行,并且所有其他进程都作为主管的子进程运行.

  • @frankster然后你用它 (2认同)