Django rq 的 Supervisord 配置不起作用
Supervisord configuration for Django rq not working
我正在关注:Putting RQ under supervisor
我的工作:
@job("default")
def send_mail(subject, body, sender, receivers, cc=None, bcc=None, content_type='plain', class_name=None):
"""Send email to users."""
*code to send mail.*
当我运行
python manage.py rqworker
我能够使用 rq 队列执行任务。
但不适用于 supervisord 配置。
主管配置:
路径:/etc/supervisord/conf.d/filename.conf
[program:myworker]
; Point the command to the specific rq command you want to run.
; If you use virtualenv, be sure to point it to
; /path/to/virtualenv/bin/rq
; Also, you probably want to include a settings module to configure this
; worker. For more info on that, see http://python-rq.org/docs/workers/
command= /home/user/.virtualenvs/my_project/bin/rq worker
process_name=%(program_name)s
stdout_logfile = /var/log/my_project/redis.log
; If you want to run more than one worker instance, increase this
numprocs=1
; This is the directory from which RQ is ran. Be sure to point this to the
; directory where your source code is importable from
directory=/home/user/github_my_projects/projects/my_project
; RQ requires the TERM signal to perform a warm shutdown. If RQ does not die
; within 10 seconds, supervisor will forcefully kill it
stopsignal=TERM
; These are up to you
autostart=true
autorestart=true
回答我自己的问题。
这是我在本地和开发服务器中使用的示例配置。
您可以使用以下方式创建此文件:
sudo touch /etc/supervisor/conf.d/djangorq.conf
开发服务器配置:
[program:djangorq]
command=/root/.virtualenvs/my_project/bin/rqworker
stdout_logfile=/var/log/my_project/redis.log
user=root
numprocs=1
directory=/var/www/cast-core/my_project
environment=DJANGO_CONFIGURATION=Local,DJANGO_SETTINGS_MODULE=config.local,PYTHONPATH=/var/www/projects/my_project
stopsignal=TERM
; These are up to you
autostart=true
autorestart=true
本地环境:
[program:myworker]
command= /home/user/.virtualenvs/my_project/bin/rqworker
stdout_logfile = /var/log/my_project/redis.log
numprocs=1
directory=/home/user/github_projects/projects/my_project
environment=DJANGO_CONFIGURATION=Local,DJANGO_SETTINGS_MODULE=config.local,PYTHONPATH=/home/user/github_projects/cast-core/my_project
user = root
stopsignal=TERM
autostart=true
autorestart=true
在此之后你启动 supervisor 和 supervisorctl
sudo service supervisor start
然后
supervisorctl reload
然后使用 :
将您的作业排入队列
send_mail.delay(#params_required_for_send_mail_method)
我是这样解决的
首先是我的 supervisord.conf(将其放在 /etc/supervisor/ 中)。默认的主要变化是将日志文件放在我可以管理它们的地方(即我的其他日志文件所在的地方)
; supervisor config file
[unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
[supervisord]
logfile=/home/ubuntu/backend/logs/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/home/ubuntu/backend/logs/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/home/ubuntu/backend/logs/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:///tmp/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
运行 rqworks 的配置如下所示:(放在文件 /etc/supervisor/conf.d/rqworker.conf 中)。对于此文件,请注意目录。我还将用户更改为与 运行 我的网站相同的用户:
[program:rqworker]
command= /home/ubuntu/backend/opt/api/deploy_env/bin/python manage.py rqworker
process_name=%(program_name)%(process_num)s
; If you want to run more than one worker instance, increase this
numprocs=2
user=ubuntu
; This is the directory from which RQ is ran. Be sure to point this to the
; directory where your source code is importable from
directory=/home/ubuntu/backend/opt/api/django_project/
; RQ requires the TERM signal to perform a warm shutdown. If RQ does not die
; within 10 seconds, supervisor will forcefully kill it
stopsignal=TERM
autostart=true
autorestart=true
我正在关注:Putting RQ under supervisor
我的工作:
@job("default")
def send_mail(subject, body, sender, receivers, cc=None, bcc=None, content_type='plain', class_name=None):
"""Send email to users."""
*code to send mail.*
当我运行
python manage.py rqworker
我能够使用 rq 队列执行任务。 但不适用于 supervisord 配置。 主管配置:
路径:/etc/supervisord/conf.d/filename.conf
[program:myworker]
; Point the command to the specific rq command you want to run.
; If you use virtualenv, be sure to point it to
; /path/to/virtualenv/bin/rq
; Also, you probably want to include a settings module to configure this
; worker. For more info on that, see http://python-rq.org/docs/workers/
command= /home/user/.virtualenvs/my_project/bin/rq worker
process_name=%(program_name)s
stdout_logfile = /var/log/my_project/redis.log
; If you want to run more than one worker instance, increase this
numprocs=1
; This is the directory from which RQ is ran. Be sure to point this to the
; directory where your source code is importable from
directory=/home/user/github_my_projects/projects/my_project
; RQ requires the TERM signal to perform a warm shutdown. If RQ does not die
; within 10 seconds, supervisor will forcefully kill it
stopsignal=TERM
; These are up to you
autostart=true
autorestart=true
回答我自己的问题。
这是我在本地和开发服务器中使用的示例配置。 您可以使用以下方式创建此文件:
sudo touch /etc/supervisor/conf.d/djangorq.conf
开发服务器配置:
[program:djangorq]
command=/root/.virtualenvs/my_project/bin/rqworker
stdout_logfile=/var/log/my_project/redis.log
user=root
numprocs=1
directory=/var/www/cast-core/my_project
environment=DJANGO_CONFIGURATION=Local,DJANGO_SETTINGS_MODULE=config.local,PYTHONPATH=/var/www/projects/my_project
stopsignal=TERM
; These are up to you
autostart=true
autorestart=true
本地环境:
[program:myworker]
command= /home/user/.virtualenvs/my_project/bin/rqworker
stdout_logfile = /var/log/my_project/redis.log
numprocs=1
directory=/home/user/github_projects/projects/my_project
environment=DJANGO_CONFIGURATION=Local,DJANGO_SETTINGS_MODULE=config.local,PYTHONPATH=/home/user/github_projects/cast-core/my_project
user = root
stopsignal=TERM
autostart=true
autorestart=true
在此之后你启动 supervisor 和 supervisorctl
sudo service supervisor start
然后
supervisorctl reload
然后使用 :
将您的作业排入队列send_mail.delay(#params_required_for_send_mail_method)
我是这样解决的
首先是我的 supervisord.conf(将其放在 /etc/supervisor/ 中)。默认的主要变化是将日志文件放在我可以管理它们的地方(即我的其他日志文件所在的地方)
; supervisor config file
[unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
[supervisord]
logfile=/home/ubuntu/backend/logs/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/home/ubuntu/backend/logs/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/home/ubuntu/backend/logs/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:///tmp/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
运行 rqworks 的配置如下所示:(放在文件 /etc/supervisor/conf.d/rqworker.conf 中)。对于此文件,请注意目录。我还将用户更改为与 运行 我的网站相同的用户:
[program:rqworker]
command= /home/ubuntu/backend/opt/api/deploy_env/bin/python manage.py rqworker
process_name=%(program_name)%(process_num)s
; If you want to run more than one worker instance, increase this
numprocs=2
user=ubuntu
; This is the directory from which RQ is ran. Be sure to point this to the
; directory where your source code is importable from
directory=/home/ubuntu/backend/opt/api/django_project/
; RQ requires the TERM signal to perform a warm shutdown. If RQ does not die
; within 10 seconds, supervisor will forcefully kill it
stopsignal=TERM
autostart=true
autorestart=true