是否可以在同一个监督下拥有2个django实例?

时间:2013-01-21 14:08:41

标签: django deployment supervisord

我有一个django应用程序,它有两个在同一台服务器上运行的实例:生产和暂存。我使用virtualenv,每个实例都有自己的env。它们配置如下:

  • 生产(myapp.com):服务器在端口8001上运行.Apache代理80到8001.
  • 暂存(myapp.com:5000):服务器在端口5001上运行.Apache代理5000到5001.

好吧,我手动启动服务器,所有完美运行

现在,我正在尝试使用主管来单独管理和部署它们,以便更好地组织和更轻松地部署。我得到的是一些非常奇怪的东西!生产服务器工作正常,但登台服务器响应,因为它是生产服务器!

如果我不使用supervisord,我会分别访问myapp.com和myapp.com:5000并查看生产和登台代码。但是,当我使用supervisord时,我会在两者上看到生产代码。这很奇怪,似乎主管将请求发送到错误的流程 ...:S

有可能做我正在尝试的事情吗?在同一个supervisor.conf上运行2个web服务器是否存在已知问题?有人任何线索,好吗? = /


supervisor.conf(相关部分)

;;;;;;;;;; supervisord configuration ;;;;;;;;;;
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
;umask=022                   ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value       ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

;;;;;;;;;; applications configuration ;;;;;;;;;;
[program:staging]
command=python manage.py celeryd -B --loglevel=info --settings=settings.staging
command=python manage.py run_gunicorn --workers=2 --bind=127.0.0.1:5001 --settings=settings.staging
autostart=false

[program:production]
command=python manage.py celeryd -B --loglevel=info --settings=settings.production
command=python manage.py run_gunicorn --workers=2 --bind=127.0.0.1:8001 --settings=settings.production
autostart=false

obs:用于初始化网络服务器的命令是上面程序部分的命令。


非常感谢!

2 个答案:

答案 0 :(得分:0)

我将使用主管描述我的设置以试图揭开一些亮点。我有一个管理8个站点的主管守护程序。在我的例子中,每个程序都是一个uWSGI进程(假设为gunicorn)。每个进程都通过UNIX套接字进行通信。我有单独的nginx条目(假设为Apache)绑定到相应的套接字(uWSGI进程建立)。同样,每个nginx条目都在Web服务器上自己的端口上运行(可选择使用自定义主机名)。

主管的角色是管理流程的生命周期,基本上通过某些名称为每个注册流程提供一个控制点,例如: production。我不认为问题存在于主管路由到错误的进程,因为这不是它的作用。那个run_gunicorn命令是在后台还是前台运行进程?为了让主管管理这个过程,它必须没有被守护。

答案 1 :(得分:0)

Supervisord documentation about subprocesses说:

  

子进程将继承用于启动supervisord程序的shell的环境。

我的问题是我为每个实例都有单独的virtualenvs,但是supervisord进程首先使用生产实例初始化。所以是的,可以在同一个主管上安装多个django实例,但不能在每个实例上使用不同的虚拟实例。

相关问题