主管 celeryd 的用户不正确

发布于 2024-12-29 05:53:41 字数 961 浏览 3 评论 0原文

我有一些使用 celery 运行的定期任务(由supervisord 守护),但是在尝试在用户的主目录中创建一个目录后,我为supervisord 进程设置了一个“权限被拒绝”错误。在查看正在运行的 celery 任务中的 os.environ 字典后,我注意到 USER var 设置为“root”,而不是我在 Supervisord 中设置的用户芹菜的配置。

这就是我的 /usr/local/etc/supervisord.conf 的样子:

[unix_http_server]
file=/tmp/supervisor.sock
chmod=0777

[supervisord]
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid

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

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[program:celery]
command=/home/<USER>/.virtualenvs/sync/bin/celeryd --beat --loglevel=INFO
environment=PYTHONPATH=/home/<USER>/apps/sync
directory=/home/<USER>/apps/sync
user=<USER>
numprocs=1
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 30

可能是什么原因造成的?任何帮助将不胜感激!

I have some periodic tasks that I run with celery (daemonized by supervisord), but after trying to create a directory in the home dir for the user i setup for the supervisor'd process I got a "permission denied" error. After looking at the os.environ dict in a running celery task I noticed that the USER var is set to 'root' and not the user that I set up in my supervisord config for celery.

This is what my /usr/local/etc/supervisord.conf looks like:

[unix_http_server]
file=/tmp/supervisor.sock
chmod=0777

[supervisord]
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid

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

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[program:celery]
command=/home/<USER>/.virtualenvs/sync/bin/celeryd --beat --loglevel=INFO
environment=PYTHONPATH=/home/<USER>/apps/sync
directory=/home/<USER>/apps/sync
user=<USER>
numprocs=1
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 30

What could be causing this? Any help would be super appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拔了角的鹿 2025-01-05 05:53:41

我认为这是由于您没有设置 HOME 和 USER 环境变量引起的。如果您的子流程依赖于正在设置的子流程,则在使用“user =”选项时这是必要的。

在有关 子流程环境 的主管文档之后:

supervisord 在运行子进程时不会执行任何 shell,因此 USER、PATH、HOME、SHELL、LOGNAME 等环境变量不会更改其默认值或以其他方式重新分配

所以也许可以尝试:

environment=USER=<USER>,HOME=/home/<USER>,PYTHONPATH=/home/<USER>/apps/sync

I believe this is caused by the fact that you didn't set the HOME and USER environment variables. This is necessary when using the "user=" option if your subprocess relies on those being set.

After supervisord documentation on Subprocess Environment:

No shell is executed by supervisord when it runs a subprocess, so environment variables such as USER, PATH, HOME, SHELL, LOGNAME, etc. are not changed from their defaults or otherwise reassigned

So perhaps try:

environment=USER=<USER>,HOME=/home/<USER>,PYTHONPATH=/home/<USER>/apps/sync
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文