使用supervisor和virtualenv监控celerybeat

14

我的 celerybeat.conf

[program:celerybeat]
command=/path/app/env/bin/celery beat -A project.tasks --loglevel=INFO
environment=PYTHONPATH=/path/app/env/bin

user=nobody
numprocs=1
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998

当我启动supervisor时,我收到一个错误:

pidfile_fd = os.open(self.path, PIDFILE_FLAGS, PIDFILE_MODE)
celery.platforms.LockFailed: [Errno 13] Permission denied: '/celerybeat.pid'

有什么想法解决这个问题吗?

4个回答

16

问题在于您在配置文件中没有指定任何目录,因此默认目录为“/”(根目录),而您的用户没有写入权限。

将用户设置为root解决了您的问题,因为现在您有写入“/”的权限,但这可能不是最佳解决方案。有多种方法可以解决此问题,包括:

  1. Add a directory variable in the config and provide a path that your user has permissions to write to.

    directory=<path>
    
  2. Provide a pidfile argument to the celery command that you are using to start celery. Make sure you have write permissions to the path you specify for the pidfile.

    command=/path/app/env/bin/celery beat -A project.tasks --loglevel=INFO --pidfile=/tmp/celerybeat-myapp.pid
    

在将“--pidfile”自定义添加到tmp目录后,运行良好。 - Joni

1

这是我关于Celere beat的(可行的)版本:

[program:celery_periodic]
command=<venv_path>/bin/python <path>/manage.py celery worker --loglevel=info -c 1 -E -B -Q celery_periodic -f <log_folder>/celery_periodic.log -n periodic_worker
directory=<path>
user=<some_user>
group=<some_user>
autostart=true
autorestart=true
redirect_stderr=True
daemon = False
debug = False
stdout_logfile = NONE
stderr_logfile = NONE
loglevel = "info"

也许这能帮到你。
在创建pid文件的文件夹中查看权限。

不建议在生产环境中在celery worker内部启动beat。http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html - RunLoop
这个注释是指Celery的某个第二版。当时这是一种标准的做法。现在不确定情况如何。 - Artem Mezhenin

0

我遇到了类似的问题,通过更改两个设置来解决:

  1. 如上所述:添加--pidfile=/tmp/celerybeat-myapp.pid
  2. 用户="一个实际的非root用户"

有些文档中提供的默认值"user = nobody"似乎会导致在celerybeat.conf中出现额外的权限错误(但不在celery.conf中)。


0

我通过将用户设置为root来解决我的问题,但我认为这是不好的方式...


4
不要这样做!尽可能少地使用root权限。最好遵循@sanchitarora的回答,并将pid文件写入您拥有写入访问权限的目录中。 --pidfile=/tmp/celerybeat-myapp.pid - j7nn7k

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接