加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – celery守护程序 – 日志文件中的权限被拒绝

发布时间:2020-12-16 21:29:57 所属栏目:Python 来源:网络整理
导读:我一直在努力将我的celery任务设置为守护进程,以便按计划处理数据. 我一直在关注the docs以便设置我的守护进程,但是一直遇到一个日志文件权限错误让我难过. 以下是我在Digital Ocean上的ubuntu盒子上设置的配置 在/ etc /默认/ celeryd # here we have a sin
我一直在努力将我的celery任务设置为守护进程,以便按计划处理数据.

我一直在关注the docs以便设置我的守护进程,但是一直遇到一个日志文件权限错误让我难过.

以下是我在Digital Ocean上的ubuntu盒子上设置的配置

在/ etc /默认/ celeryd

# here we have a single node
CELERYD_NODES="w1"

CELERY_BIN = "/mix_daemon/venv/bin/celery"
CELERYD_CHDIR="/mix_daemon/"

CELERYD_OPTS="-A tasks worker --loglevel=info --beat"

# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERY_CREATE_RUNDIR=0
CELERY_CREATE_LOGDIR=0

# Workers should run as an unprivileged user.
CELERYD_USER="celery"
CELERYD_GROUP="celery"

但是,当我跑

sh -x /etc/init.d/celeryd start

我收到以下错误消息:

celery multi v3.1.7 (Cipater)
> Starting nodes...
> celery@mix: OK
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py",line 162,in _run_module_as_main
"__main__",fname,loader,pkg_name)
File "/usr/lib/python2.7/runpy.py",line 72,in _run_code
exec code in run_globals
File "/home/john/mix_daemon/venv/lib/python2.7/site-packages/celery/bin/celeryd_detach.py",line 168,in <module> main()
File "/home/john/mix_daemon/venv/lib/python2.7/site-packages/celery/bin/celeryd_detach.py",line 165,in main
detached_celeryd(app).execute_from_commandline()
File "/home/john/mix_daemon/venv/lib/python2.7/site-packages/celery/bin/celeryd_detach.py",line 160,in execute_from_commandline
**vars(options)
File "/home/john/mix_daemon/venv/lib/python2.7/site-packages/celery/bin/celeryd_detach.py",line 42,in detach
with detached(logfile,pidfile,uid,gid,umask,working_directory,fake):
File "/home/john/mix_daemon/venv/local/lib/python2.7/site-packages/celery/platforms.py",line 314,in open
self.after_chdir()
File "/home/john/mix_daemon/venv/local/lib/python2.7/site-packages/celery/platforms.py",line 384,in after_chdir_do
logfile and open(logfile,'a').close()
IOError: [Errno 13] Permission denied: '/var/log/celery/celery.log'
+ sleep 5
+ exit 0

我看了这个错误信息并从redmine项目中看到了this answer.所以我尝试了以下尝试允许芹菜工作者写入日志文件:

$sudo mkdir -p -m 2755 /var/log/celery
$sudo chown celery:celery /var/log/celery

但是当我尝试启动守护进程时仍然存在相同的错误.

我是一个芹菜菜鸟,对此的任何帮助将不胜感激!

解决方法

根据文件:

The init scripts can only be used by root,and the shell configuration file must also be owned by root”

所以,你需要运行:

sudo chown root:root /etc/default/celeryd

sudo /etc/init.d/celeryd start

顺便说一句,你的celeryd配置文件中的语法无效:

CELERY_BIN = "/mix_daemon/venv/bin/celery"

“=”运算符不允许使用空格,正确的是:

CELERY_BIN="/mix_daemon/venv/bin/celery"

还要检查/ bin / mix_daemon中的bin是不是/ home // mix_daemon

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读