【发布时间】:2026-02-18 09:50:01
【问题描述】:
我有一个 Django 应用程序,我使用 Celery 来运行后台任务。
我正在使用主管将 celery 作为服务运行,但是当我运行时:sudo supervisorctl reread,它给了我以下错误:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 578, in _build_master
ws.require(__requires__)
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 895, in require
needed = self.resolve(parse_requirements(requirements))
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 786, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (supervisor 4.0.0.dev0 (/home/user/.local/lib/python3.6/site-packages),
Requirement.parse('supervisor==3.3.1'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/supervisorctl", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3112, in <module>
@_call_aside
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3096, in _call_aside
f(*args, **kwargs)
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3125, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 580, in _build_master
return cls._build_from_requirements(__requires__)
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 593, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/home/user/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 781, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'supervisor==3.3.1' distribution was not found and is required by the application
用supervisiord配置文件更新:-
supervisord.conf:
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log
file;default
$CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default
supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory =
supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a
unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
Celery 配置文件:
celery_proj_worker.conf
; ==================================
; celery worker supervisor example
; ==================================
; the name of your supervisord program
[program:proj_worker]
; Set full path to celery program if using virtualenv
command=/home/me/proj/venv/bin/celery -A proj worker -l info
; The directory to your Django project
directory=/home/me/proj
; If supervisord is run as the root user, switch users to this UNIX
user account before doing any processing.
user=me
; Supervisor will start as many instances of this program as named by
numprocs
numprocs=1
; Put process stdout output in this file
stdout_logfile=/var/log/celery/proj_worker.log
; Put process stderr output in this file
stderr_logfile=/var/log/celery/proj_worker.log
; If true, this program will start automatically when supervisord is
started
autostart=true
; May be one of false, unexpected, or true. If false, the process will never be autorestarted. If unexpected, the process will be restart when the program exits with an exit code that is not one of the exit codes associated with this process’ configuration (see exitcodes). If true, the process will be unconditionally restarted when it exits, without regard to its exit code.
autorestart=true
; The total number of seconds which the program needs to stay running after a startup to consider the start successful.
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 your broker is supervised, set its priority higher so it starts first
priority=998
celery_proj_beat.conf
; ================================
; celery beat supervisor example
; ================================
; the name of your supervisord program
[program:projbeat]
; Set full path to celery program if using virtualenv
command=/home/me/proj/venv/bin/celery -A proj beat -l info
; The directory to your Django project
directory=/home/me/proj
; If supervisord is run as the root user, switch users to this UNIX
user account before doing any processing.
user=me
; Supervisor will start as many instances of this program as named by numprocs
numprocs=1
; Put process stdout output in this file
stdout_logfile=/var/log/celery/proj_beat.log
; Put process stderr output in this file
stderr_logfile=/var/log/celery/proj_beat.log
; If true, this program will start automatically when supervisord is started
autostart=true
; May be one of false, unexpected, or true. If false, the process will never be autorestarted. If unexpected, the process will be restart when the program exits with an exit code that is not one of the exit codes associated with this process’ configuration (see exitcodes). If true, the process will be unconditionally restarted when it exits, without regard to its exit code.
autorestart=true
; The total number of seconds which the program needs to stay running after a startup to consider the start successful.
startsecs=10
; if your broker is supervised, set its priority higher so it starts first
priority=999
欢迎提出任何建议。 提前致谢。
【问题讨论】:
-
你能发布你的主管配置文件吗?
-
@CoolestNerdIII 请检查,我已经用 supervisord.conf 文件更新了我的问题。
-
你能用你的芹菜配置显示文件吗?
-
@CoolestNerdIII 请检查更新的问题。
-
1.在您的 celery beat 文件中,我相信您的目录与所有其他目录不同
标签: django celery supervisord