0

I have a JQuery request for JSON data in my Django app (which started in vitrualenv with uwsgi and nginx):

$.getJSON( url, function( data ) {
    var obl  = "/raj/?raj=" + data.id;
    $.getJSON( obl, function( raj_data ) {
        ...
        } );
    } );

and corresponding view:

def rcoato(request):
    response_data = SprRegion.objects.values('id').get(Q(id=request.GET['region']))
    response_data = json.dumps(response_data)
    return HttpResponse(response_data, content_type='application/javascript')

It works fine, JSON data returned, but only when I logged in via SSH. I and start my application with:

source virtualenv/bin/activate
uwsgi --xml /home/rino/sites/centre/uwsgi.xml & 

When I logged out (with setopt no_hup and setopt no_checkjobs), my app works partially - HTML pages are rendering, static files are handling, but requests to /raj/?raj=... raises Internal Server Error 500.

My nginx.conf:

server {
       listen 8081;
       server_name localhost;
       access_log /var/log/nginx/nginx_centre_access.log;
       error_log /var/log/nginx/nginx_centre_error.log;

       location /static {    
           autoindex on;    
           alias /home/rino/sites/centre/centre/static/;    
       }

       location / {
           uwsgi_pass 127.0.0.1:3031;
           include /home/rino/sites/centre/uwsgi_params;
       }
}

uwsgi config:

<uwsgi>
  <socket>127.0.0.1:3031</socket>
  <processes>5</processes>
  <pythonpath>/home/rino/sites/centre</pythonpath>
  <chdir>/home/rino/sites/centre/centre</chdir>
  <wsgi-file>/home/rino/sites/centre/centre/wsgi.py</wsgi-file>
  <pidfile>/tmp/centre-master.pid</pidfile>
  <plugin>python3</plugin>
  <max-requests>5000</max-requests>
  <harakiri>40</harakiri>
  <master>true</master>
  <threads>2</threads>
</uwsgi>

cat nginx_centre_error.log | tail after logout and querying request described above:

2014/10/03 07:34:46 [error] 20657#0: *296 connect() failed (111: Connection refused) 
while connecting to upstream, client: 176.100.173.177, server: localhost, request: "GET 
/settler/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "myhost.com:8081",   
referrer:  "http://myhost.com/settlersmain/"

2014/10/03 07:56:55 [error] 20657#0: *335 connect() failed (111: Connection refused) 
while connecting to upstream, client: 176.100.173.177, server: localhost, request: 
"GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "myhost.com:8081"
2014/10/03 08:23:33 [error] 20657#0: *367 open()

Thanks for any help!

UPD: I replace localhost in server_name line of nginx.conf with server IP address, but issue is still present.

codkelden
  • 332
  • 6
  • 9

1 Answers1

1

According to your log you have (111: Connection refused) error, and it means that uwsgi process is killed after you close ssh connection.

You can try this instruction to use nohup.

uWSGI has an option to daemonize. This is a better way, uWSGI will handle detaching from console.

But I suggest you use something like supervisord to run uWSGI. Or you can use your system's init.d scripts or Upstart

Community
  • 1
  • 1
Igor
  • 3,129
  • 1
  • 21
  • 32
  • Daemonize is the way to go. If you can't explain a service dying, having it automatically restarted isn't the best course of action in my experience, but ymmv. –  Oct 03 '14 at 17:32
  • Daemonize will work if process is killed due to log out i.e. `setopt no_hup` does not work. But if it dies for another reason (some un-handled exception) it will continue dying in daemon mode. Try to setup uwsgi logging with `logto` and check what causes it to exit – Igor Oct 03 '14 at 21:30
  • @Igor, I use Upstart config which run uwsgi. Works fine, thank you. – codkelden Oct 05 '14 at 12:55