title: uWSGI Emperor configuration
body: <p>I have been struggling to deploy a flask app to my server using uWSGI in
  Emperor mode all day and am at a loss why it is not working.  I have read all the other uWSGI Emperor mode questions here &amp; asked on #uwsgi &amp; the mailing list with no reply.</p>
  
  <p>My setup is nginx (1.4.6-1ubuntu3.2), uWSGI==2.0.10 installed via pip
  into a virtualenv, Flask==0.10.1, and Python 3.4.0.  supervisord is
  responsible for launching the Emperor process.</p>
  
  <p>The flask app itself works fine when I start it manually bound to a TCP port, and when I manually run uwsgi like:</p>
  
  <pre><code>uwsgi -s /tmp/oauthsvc.sock -w wsgi --stats /tmp/oauthsvc-stats.sock
  </code></pre>
  
  <p>I do notice that even though I think I configured the vassal to use a
  unix socket, it reports on startup that it is listening to <a href="http://127.0.0.1:5000/" rel="nofollow">http://127.0.0.1:5000/</a></p>
  
  <p>I verified with strace that nginx is opening the socket, and permissions
  of that socket are 777:</p>
  
  <pre><code>srwxrwxrwx 1 oauthsvc oauthsvc 0 Jun  3 18:34 /tmp/oauthsvc.sock
  srwxrwxrwx 1 oauthsvc oauthsvc 0 Jun  3 18:08 /tmp/oauthsvc-stats.sock
  </code></pre>
  
  <p>But the connection eventually just times out.</p>
  
  <p>My configs &amp; some log output follows.</p>
  
  <p>The nginx config is as simple as can be:</p>
  
  <pre><code>server {                                                                    
      listen 80;                                                              
      server_name default;                                                    
  
      location = /robots.txt  { access_log off; log_not_found off; }          
      location = /favicon.ico { access_log off; log_not_found off; }          
  
      location / {                                                            
          include uwsgi_params;                                               
          uwsgi_pass unix:/tmp/oauthsvc.sock;                                 
      }                                                                       
  } 
  </code></pre>
  
  <p>supervisor launches the emporer process with this command:</p>
  
  <pre><code>[program:oauthsvc-emperor]                                                      
  command=/services/oauthsvc/services/oauthsvc/bin/uwsgi --emperor /services/oauthsvc/etc/uwsgi/vassals --die-on-term --uid 1005 --gid 1005 --logto /services/oauthsvc/var/log/uwsgi/emperor.log
  user=oauthsvc                                                                   
  autostart=true                                                                  
  autorestart=true                                                                
  redirect_stderr=true 
  </code></pre>
  
  <p>The vassal's ini file looks like:</p>
  
  <pre><code>[uwsgi]                                                                         
  # do not turn on master mode when spawned by emperor                            
  # http://stackoverflow.com/questions/15055002/uwsgi-master-with-emperor-spawns-two-emperors
  #master = true                                                                  
  protocol = uwsgi                                                                
  socket = /tmp/oauthsvc.sock                                                     
  stats = /tmp/oauthsvc-stats.sock                                                
  daemonize = /services/oauthsvc/var/log/uwsgi/oauthsvc.log                       
  chdir = /services/oauthsvc/services/oauthsvc/oauthsvc-server                    
  wsgi-file = wsgi.py                                                             
  callable = app                                                                  
  chmod-socket = 777                                                              
  uid = 1005                                                                      
  gid = 1005                                                                      
  virtualenv = /services/oauthsvc/services/oauthsvc                               
  # PYTHONHOME                                                                    
  home = /services/oauthsvc/services/oauthsvc                                     
  #env =                                                                           
  processes = 4
  vacuum = true                                                                   
  # If you start uWSGI without threads, the Python GIL will not be enabled, so    
  # threads generated by your application will never run unless you include:      
  enable-threads = true
  harakiri = 30
  </code></pre>
  
  <p>And finally, wsgi.py:</p>
  
  <pre><code>#!/usr/bin/env python3                                                          
  
  from oauthsvc.flask.server import parse_args, configured_app                    
  
  args = parse_args()                                                             
  app = configured_app(args.config, debug=args.debug)                             
  app.run()  
  </code></pre>
  
  <p>The emperor log:</p>
  
  <pre><code>*** Starting uWSGI 2.0.10 (64bit) on [Wed Jun  3 18:34:25 2015] ***
  compiled with version: 4.8.2 on 03 June 2015 18:32:12
  os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
  nodename: ip-10-0-1-224
  machine: x86_64
  clock source: unix
  pcre jit disabled
  detected number of CPU cores: 1
  current working directory: /
  detected binary path: /services/oauthsvc/src/bs-oauth-svc.2015-06-03.183113/bin/uwsgi
  *** WARNING: you are running uWSGI without its master process manager ***
  your processes number limit is 30038
  your memory page size is 4096 bytes
  detected max file descriptor number: 1024
  *** starting uWSGI Emperor ***
  *** has_emperor mode detected (fd: 6) ***
  [uWSGI] getting INI configuration from oauthsvc.ini
  </code></pre>
  
  <p>The vassal log:</p>
  
  <pre><code>*** Starting uWSGI 2.0.10 (64bit) on [Wed Jun  3 18:34:25 2015] ***
  compiled with version: 4.8.2 on 03 June 2015 18:32:12
  os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
  nodename: ip-10-0-1-224
  machine: x86_64
  clock source: unix
  pcre jit disabled
  detected number of CPU cores: 1
  current working directory: /services/oauthsvc/etc/uwsgi/vassals
  detected binary path: /services/oauthsvc/src/bs-oauth-svc.2015-06-03.183113/bin/uwsgi
  chdir() to /services/oauthsvc/services/oauthsvc/oauthsvc-server
  your processes number limit is 30038
  your memory page size is 4096 bytes
   *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
  detected max file descriptor number: 1024
  lock engine: pthread robust mutexes
  thunder lock: disabled (you can enable it with --thunder-lock)
  uwsgi socket 0 bound to UNIX address /tmp/oauthsvc.sock fd 3
  Python version: 3.4.0 (default, Apr 11 2014, 13:08:40)  [GCC 4.8.2]
  Set PythonHome to /services/oauthsvc/services/oauthsvc
  Python main interpreter initialized at 0x135d4d0
  python threads support enabled
  your server socket listen backlog is limited to 100 connections
  your mercy for graceful operations on workers is 60 seconds
  mapped 363840 bytes (355 KB) for 4 cores
  *** Operational MODE: preforking ***
   * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  </code></pre>