使用主管运行芹菜作为守护程序不起作用

时间:2022-02-24 19:15:05

I have a django app in which it has a celery functionality, so i can able to run the celery sucessfully like below

我有一个django应用程序,它有芹菜功能,所以我能够成功运行芹菜如下

celery -A tasks worker --loglevel=info

but as a known fact that we need to run it as a daemon and so i have written the below celery.conf file inside /etc/supervisor/conf.d/ folder

但作为一个众所周知的事实,我们需要将它作为一个守护进程运行,所以我在/etc/supervisor/conf.d/文件夹中编写了下面的celery.conf文件

; ==================================
;  celery worker supervisor example
; ==================================

[program:celery]
; Set full path to celery program if using virtualenv
command=/root/Envs/proj/bin/celery -A app.tasks worker --loglevel=info

user=root
environment=C_FORCE_ROOT="yes"
environment=HOME="/root",USER="root"
directory=/root/apps/proj/structure
numprocs=1
stdout_logfile=/var/log/celery/worker.log
stderr_logfile=/var/log/celery/worker.log
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998

but when i tried to update the supervisor like supervisorctl reread and supervisorctl update i was getting the message from supervisorctl status

但当我尝试更新主管,如supervisorctl重读和supervisorctl更新我从supervisorctl状态获取消息

celery                           FATAL      Exited too quickly (process log may have details)

So i went to worker.log file and seen the error message as below

所以我去了worker.log文件,看到如下错误信息

Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea!

If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do).

User information: uid=0 euid=0 gid=0 egid=0

So why it was complaining about C_FORCE_ROOT even though we had set it as environment variable inside supervisor conf file ? what am i doing wrong in the above conf file ?

那么为什么它抱怨C_FORCE_ROOT,即使我们已经将它设置为管理员conf文件中的环境变量?我在上面的conf文件中做错了什么?

3 个解决方案

#1


2  

You'll need to run celery with a non superuser account, Please remove following lines from your config:

您需要使用非超级用户帐户运行芹菜,请从配置中删除以下行:

user=root
environment=C_FORCE_ROOT="yes"
environment=HOME="/root",USER="root"

And the add these lines to your config, I assume that you use django as a non superuser and developers as the user group:

并将这些行添加到您的配置中,我假设您将django用作非超级用户,将开发人员用作用户组:

user=django
group=developers

Note that subprocesses will inherit the environment variables of the shell used to start supervisord except for the ones overridden here and within the program’s environment option. See supervisord documents.

请注意,子进程将继承用于启动supervisord的shell的环境变量,除了在此处和程序的环境选项中重写的那些变量。见监督文件。

So Please note that when you change environment variables via supervisor config files, Changes won't apply by running supervisorctl reread and supervisorctl reload . You should run supervisor from the very start by following command:

因此请注意,当您通过超级用户配置文件更改环境变量时,通过运行supervisorctl reread和supervisorctl reload将不会应用更改。您应该从一开始就通过以下命令运行supervisor:

supervisord -c /path/to/config/file.conf

#2


2  

I had the same problem,so I added

我有同样的问题,所以我补充说

environment=C_FORCE_ROOT="yes" 

in my program config,but It didn't work so I used

在我的程序配置中,但它没有工作,所以我使用

environment=C_FORCE_ROOT="true"

it's working

它正在工作

#3


1  

From this other thread on *. I managed to add the following settings and it worked for me.

从*上的这个其他线程。我设法添加以下设置,它对我有用。

app.conf.update(
    CELERY_ACCEPT_CONTENT = ['json'],
    CELERY_TASK_SERIALIZER = 'json',
    CELERY_RESULT_SERIALIZER = 'json',
)

#1


2  

You'll need to run celery with a non superuser account, Please remove following lines from your config:

您需要使用非超级用户帐户运行芹菜,请从配置中删除以下行:

user=root
environment=C_FORCE_ROOT="yes"
environment=HOME="/root",USER="root"

And the add these lines to your config, I assume that you use django as a non superuser and developers as the user group:

并将这些行添加到您的配置中,我假设您将django用作非超级用户,将开发人员用作用户组:

user=django
group=developers

Note that subprocesses will inherit the environment variables of the shell used to start supervisord except for the ones overridden here and within the program’s environment option. See supervisord documents.

请注意,子进程将继承用于启动supervisord的shell的环境变量,除了在此处和程序的环境选项中重写的那些变量。见监督文件。

So Please note that when you change environment variables via supervisor config files, Changes won't apply by running supervisorctl reread and supervisorctl reload . You should run supervisor from the very start by following command:

因此请注意,当您通过超级用户配置文件更改环境变量时,通过运行supervisorctl reread和supervisorctl reload将不会应用更改。您应该从一开始就通过以下命令运行supervisor:

supervisord -c /path/to/config/file.conf

#2


2  

I had the same problem,so I added

我有同样的问题,所以我补充说

environment=C_FORCE_ROOT="yes" 

in my program config,but It didn't work so I used

在我的程序配置中,但它没有工作,所以我使用

environment=C_FORCE_ROOT="true"

it's working

它正在工作

#3


1  

From this other thread on *. I managed to add the following settings and it worked for me.

从*上的这个其他线程。我设法添加以下设置,它对我有用。

app.conf.update(
    CELERY_ACCEPT_CONTENT = ['json'],
    CELERY_TASK_SERIALIZER = 'json',
    CELERY_RESULT_SERIALIZER = 'json',
)