没有主管的django + celery + uwsgi
django + celery + uwsgi without supervisor
在开发服务器上,Django 与 celery 和 django-celery 配合良好:
python manage.py runserver
celery -A backup worker -l info -B
celerycam --frequency=10.0
在生产服务器上,我尝试 运行 芹菜:
[uwsgi]
...
master = True
smart-attach-daemon = ${path}/${name_project}/.env/bin/python ${path}/manage.py celery -A test worker -l info -B
smart-attach-daemon = ${path}/${name_project}/.env/bin/python ${path}/manage.py celerycam --frequency=10.0
但是不行。
如果没有使用主管,我怎么能 运行 这一切?
更新
它没有看到 Django,但该站点可以运行。在日志 uwsgi 中:
Mon Aug 3 16:10:57 2015 - spawned uWSGI master process (pid: 23462)
Mon Aug 3 16:10:57 2015 - spawned uWSGI worker 1 (pid: 23666, cores: 1)
Mon Aug 3 16:10:57 2015 - spawned uWSGI worker 2 (pid: 23667, cores: 1)
Mon Aug 3 16:10:57 2015 - [uwsgi-daemons] spawning "/home/1/2/3/manage.py celery -A backup worker -l info -B"
Mon Aug 3 16:10:57 2015 - [uwsgi-daemons] spawning "/home/1/2/3/manage.py celerycam --frequency=10.0"
Traceback (most recent call last):
File "/home/1/2/3/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Traceback (most recent call last):
File "/home/1/2/3/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Mon Aug 3 16:10:58 2015 - subprocess 23668 exited with code 1
Mon Aug 3 16:10:58 2015 - subprocess 23669 exited with code 1
manage.py:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backup.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
将 "smart-attach-daemon" 替换为 "attach-daemon"
您可以使用 attach-daemon
或 smart-attach-daemon
。但是,如果您使用的是 smart-attach-daemon,那么您还应该使用 pid 文件启动 celery,并在 uwsgi 中设置它的路径:
smart-attach-daemon = ${path}/${name_project}/var/celery-worker.pid ${path}/${name_project}/.env/bin/python ${path}/manage.py celery -A test worker --pidfile=${path}/${name_project}/var/celery-worker.pid -l info -B
在开发服务器上,Django 与 celery 和 django-celery 配合良好:
python manage.py runserver
celery -A backup worker -l info -B
celerycam --frequency=10.0
在生产服务器上,我尝试 运行 芹菜:
[uwsgi]
...
master = True
smart-attach-daemon = ${path}/${name_project}/.env/bin/python ${path}/manage.py celery -A test worker -l info -B
smart-attach-daemon = ${path}/${name_project}/.env/bin/python ${path}/manage.py celerycam --frequency=10.0
但是不行。 如果没有使用主管,我怎么能 运行 这一切?
更新
它没有看到 Django,但该站点可以运行。在日志 uwsgi 中:
Mon Aug 3 16:10:57 2015 - spawned uWSGI master process (pid: 23462)
Mon Aug 3 16:10:57 2015 - spawned uWSGI worker 1 (pid: 23666, cores: 1)
Mon Aug 3 16:10:57 2015 - spawned uWSGI worker 2 (pid: 23667, cores: 1)
Mon Aug 3 16:10:57 2015 - [uwsgi-daemons] spawning "/home/1/2/3/manage.py celery -A backup worker -l info -B"
Mon Aug 3 16:10:57 2015 - [uwsgi-daemons] spawning "/home/1/2/3/manage.py celerycam --frequency=10.0"
Traceback (most recent call last):
File "/home/1/2/3/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Traceback (most recent call last):
File "/home/1/2/3/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Mon Aug 3 16:10:58 2015 - subprocess 23668 exited with code 1
Mon Aug 3 16:10:58 2015 - subprocess 23669 exited with code 1
manage.py:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backup.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
将 "smart-attach-daemon" 替换为 "attach-daemon"
您可以使用 attach-daemon
或 smart-attach-daemon
。但是,如果您使用的是 smart-attach-daemon,那么您还应该使用 pid 文件启动 celery,并在 uwsgi 中设置它的路径:
smart-attach-daemon = ${path}/${name_project}/var/celery-worker.pid ${path}/${name_project}/.env/bin/python ${path}/manage.py celery -A test worker --pidfile=${path}/${name_project}/var/celery-worker.pid -l info -B