NGINX, uWSGI and Flask not running subprocess
Question: My NGINX configuration:

    
    
    server {
      server_name 127.0.0.1;
      listen 4450;
      location ~* ^/.*$ {
      include uwsgi_params;
        uwsgi_pass unix:/tmp/esrvadmin.sock;
      }
    }
    

uWSGI start up:

    
    
    uwsgi --uid root -s /tmp/esrvadmin.sock --chown-socket nobody:root \
      --file /var/www/sitios/manten/srv.py \
      --processes 2 --callable app --pidfile /var/run/edesarrollos/esrvadmin.pid
    

Python with flask code:

    
    
    import os, subprocess
    from flask import Flask, abort, request
    app = Flask(__name__)
    
    DETO_DIR = '/var/www/sitios/manten/detos'
    
    @app.route('/detonate')
    def index():
      #return str(subprocess.check_output(['ls','-l']))
      token = request.args.get('token','')
      if token != '':
         # Si no existe el directorio de detonatores, se crea
         if not os.path.exists(DETO_DIR):
           os.mkdir(DETO_DIR)
         if os.path.isfile(DETO_DIR+"/"+token):
           try:
             os.system(open(DETO_DIR+"/"+token).read())
           except Exception as ex:
             return str(ex)
           return "Reiniciado Correctamente"
         else:
           abort(404) 
      else:
        abort(404)
    
    if __name__ == "__main__":
        app.run(debug=True,host='0.0.0.0')
    

In **main** mode, i can run anything inside os.system("something args") and
receive its HTTP response, even with "service something start" and it finish
right. Also i tried with subprocess functions, no luck.

But when i run from NGINX-uWSGI, i get a waiting forever http request, of
course never response but it does the job (starting a service).

The best error description in log i found:

    
    
    2013/01/28 03:38:24 [error] 3978#0: *3 upstream timed out (110: Connection timed out) 
    while reading response header from upstream, client: 
    127.0.0.1, server: 127.0.0.1, request: "GET
    /detonate?token=start-    
    a81260812b643d8672ccf9570033109f200595779e0a352e630a75760328e2d375025ef349e
    3d599f368092abb63511f-23611e81194b04d5d0a6d0f02baf7fb9
    HTTP/1.1", upstream: "uwsgi://unix:/tmp/esrvadmin.sock:", host: "127.0.0.1:4450"
    

Any idea of what could be happening ?


Answer: read here: <http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html>
(the --close-on-exec part) and please,please, please, DO NOT RUN uWSGI as root
!

