【问题标题】:Celery beat using supervisor in productionCelery beat 在生产中使用主管
【发布时间】:2015-07-08 22:08:02
【问题描述】:

我正在尝试使用主管从我的虚拟环境中运行 celery beat。该脚本似乎不起作用

我所有的主管脚本都在目录/etc/supervisord 它有一个supervisord.conf 文件和目录conf.d,其中包含文件Gorgon-celery.conf

我的supervisord.conf 文件如下所示:

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)

[supervisord]
logfile=/var/log/supervisord/main.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
childlogdir=/var/log/supervisord            ; ('AUTO' child log dir, default $TEMP)

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[include]
files = /etc/supervisord/conf.d/*.conf

我的Gorgon-celery.conf 文件如下所示:

[program:Gorgon-celery]
command=cd /home/ubuntu/sites/source && source ../virtualenv/bin/activate && celery -A Gorgon worker
environment=PYTHONPATH=/home/ubuntu/sites/virtualenv/bin
directory=/home/ubuntu/sites/source
numprocs=1
stdout_logfile=/var/log/celeryd/Gorgon.log
stderr_logfile=/var/log/celeryd/Gorgon.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600

[program:Gorgon-celerybeat]
command=cd /home/ubuntu/sites/source && source ../virtualenv/bin/activate && celery -A Gorgon beat --max-interval=10
environment=PYTHONPATH=/home/ubuntu/sites/virtualenv/bin
directory=/home/ubuntu/sites/source
numprocs=1
stdout_logfile=/var/log/celeryd/Gorgon-beat.log
stderr_logfile=/var/log/celeryd/Gorgon-beat.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600

最后给主管,我用的是命令:sudo supervisord -c /etc/supervisord/supervisord.conf

【问题讨论】:

  • 当我使用命令ps aux | grep celery时,我得到输出:1001 23882 0.0 0.3 10468 2184 pts/2 S+ 14:37 0:00 grep --color=auto celery
  • 它在主管之外工作吗?例如,如果您将command=cd /home/sourabh_workaholic_gmail_com/sites/source && source ../virtualenv/bin/activate && celery -A Gorgon beat --max-interval=10 粘贴到外壳中。
  • 是的,它确实完美无缺。

标签: python celery supervisord celerybeat


【解决方案1】:

尝试替换

command=cd /home/sourabh_workaholic_gmail_com/sites/source && source ../virtualenv/bin/activate && celery -A Gorgon beat --max-interval=10

command=bash /home/sourabh_workaholic_gmail_com/script.sh

现在在script.sh 中输入以下内容:

#!/bin/bash    
cd /home/sourabh_workaholic_gmail_com/sites/source 
source ../virtualenv/bin/activate 
celery -A Gorgon beat --max-interval=10

我怀疑您不能将 source 命令与 supervisorctl 一起使用,因为它不会在 shell 中执行您的命令字符串。 source 是 bash shell 提供的命令,因此我们将这些命令放在它们将起作用的 bash 脚​​本中。

【讨论】:

  • 好像奏效了,买我刚刚发现了一个新的缺陷。第二个脚本似乎只运行 celerybeat 并跳过 celery。
  • 您将需要创建两个单独的 bash 脚本。一种用于芹菜,一种用于芹菜节拍。
  • 我确实这样做了。顺便说一下,我得到的输出是:ps aux|grep celeryroot 24523 0.0 0.6 67904 4188 pts/2 T 14:50 0:00 sudo nano Gorgon-celery.confroot 24524 0.0 0.7 14604 4704 pts/2 T 14:50 0:00 nano Gorgon-celery.confroot 24620 0.1 7.6 174784 45968 ? S 14:52 0:00 /home/sourabh_workaholic_gmail_com/sites/virtualenv/bin/python /home/sourabh_workaholic_gmail_com/sites/virtualenv/bin/celery -A Gorgon beat --max-interval=101001 25246 0.0 0.3 10468 2136 pts/2 S+ 15:01 0:00 grep --color=auto celery
  • 运行 celery 的 bash 脚本会发生什么
  • 没什么,它只是跳过并运行 celerybeat。我正在使用“nohup celery -A Gorgon worker &”命令让它运行。
猜你喜欢
  • 2016-10-11
  • 2019-06-09
  • 2022-01-20
  • 2017-08-07
  • 2019-11-15
  • 1970-01-01
  • 2020-06-23
  • 2015-01-01
  • 2015-06-04
相关资源
最近更新 更多