【问题标题】:Whys is Celery worker using /root as home directory?为什么 Celery worker 使用 /root 作为主目录?
【发布时间】:2015-06-18 08:26:29
【问题描述】:

我们正在使用 Celery 和 RabbitMQ 来处理作业。他们都由主管运行,以便他们可以活着。

有些作业需要用户 A 的主目录中的文件。所以我们在主管中以用户 A 的身份运行 celery worker。但是在处理作业时,它会将“~”扩展为“/root”。为什么会这样?我们如何确保它能够通过扩展 '~' 来找到主目录,因为我们的代码在很多地方都需要在 '~' 之后的文件?

【问题讨论】:

  • 您是以 root 身份运行 celery workers 还是 supervisord? (运行ps aux | grep celery查看——第一列是用户名)。
  • 通过运行上面的命令我发现Celery是由用户A运行的

标签: python rabbitmq celery supervisord


【解决方案1】:

您可能需要使用supervisorduser 配置指令以专用用户而不是root 的身份运行celery 进程。

您还应该将 chdir 显式指定为工作目录 - 在您的 celery 代码中或使用主管 directory 设置。

如果您想依靠~ 工作,您可能还应该设置环境变量$HOME。然而~ 是一个shell 扩展,它可能并不总是有效。最便携的解决方案是依赖directory 设置。

/etc/supervisor.d/celery.conf

[program:celery]
command=/path/to/celery worker
user=celery
stdout_logfile=/var/log/supervisor/celery.log
redirect_stderr=true
directory=/path/to/celery/working/dir
environment=HOME=/path/to/celery/home

【讨论】:

  • 这让我感到困惑,因为我们已经在 supervisord 的 celery 配置文件中将其设置为用户 A。
  • 啊好的。可能是环境变量 $HOME 未设置 - 我已更新我的答案以包含它。
猜你喜欢
  • 1970-01-01
  • 2018-06-08
  • 2016-09-20
  • 1970-01-01
  • 2012-03-16
  • 1970-01-01
  • 2013-10-13
  • 2014-09-01
  • 1970-01-01
相关资源
最近更新 更多