用sudo命令启动celery

时间:2019-02-13 20:33:40

标签: celery django-celery celery-task celerybeat celeryd

我正在与Celery合作,并且尝试使用sudo启动它。 sudo celery multi start worker --app=app.celery --loglevel=info --concurrency=1我需要使用sudo运行命令,但是当我这样做时,我遇到了权限错误。如何使用sudo命令启动Celery?

我尝试从文档中读取内容,但不清楚Celery Docs

sudo celery multi start worker --app=app.celery --loglevel=info --concurrency=1
celery multi v4.2.1 (windowlicker)
> Starting nodes...
    > worker@xr-npu-perf-lnx: OK
Traceback (most recent call last):
  File "/auto/pysw/cel7x/python64/3.4.1/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/auto/pysw/cel7x/python64/3.4.1/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/__main__.py", line 20, in <module>
    main()
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/__main__.py", line 16, in main
    _main()
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/celery.py", line 322, in main
    cmd.execute_from_commandline(argv)
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/celery.py", line 496, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/base.py", line 275, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/celery.py", line 488, in handle_argv
    return self.execute(command, argv)
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/celery.py", line 420, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/worker.py", line 222, in run_from_argv
    self.maybe_detach([command] + argv)
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/worker.py", line 229, in maybe_detach
    detached_celeryd(self.app).execute_from_commandline(argv)
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/celeryd_detach.py", line 99, in execute_from_commandline
    **vars(options)
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/bin/celeryd_detach.py", line 35, in detach
    after_forkers=False):
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/platforms.py", line 335, in open
    self.after_chdir()
  File "/auto/nest/xr-perf-site/xr-perf-pyats-env/lib/python3.4/site-packages/celery/platforms.py", line 412, in after_chdir_do
    logfile and open(logfile, 'a').close()
PermissionError: [Errno 13] Permission denied: 'worker.log'

1 个答案:

答案 0 :(得分:1)

由于日志目录的位置,您遇到了权限错误。您可以使用-f指定日志文件。所以也许像这样:

sudo celery multi start worker --app=app.celery --loglevel=info --concurrency=1 -f /tmp/celery.log

应该可以解决问题。如果有内存,则可能还必须将C_FORCE_ROOT env变量设置为1才能使它起作用。