Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uwsgi service is not starting

I have a python application (concrete Django) running on my server. Before yesterday, it was successfully running under apache with mod-wsgi with almost no problem. I had two main reason to switch to nginx:

  • performance - under nginx, I have almost half time for each request
  • two applications together was not running successfully under apache - solved by nginx
  • third reason is better configuration for me

I have a problem with the uwsgi service. First, I will include the app's wsgi file:

import os
import sys 

path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

if path not in sys.path:
sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "usporion.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Then I have uwsgi.ini file for init app, located under /etc/uwsgi/apps-enabled/usporion.ini:

[uwsgi]
plugins = python
uid = www-data
gid = www-data
uwsgi-socket = /srv/sockets/usporion.sock
chmod-socket = 664
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
module = usporion.wsgi
env = DJANGO_SETTINGS_MODULE=usporion.settings
logdate = True
logto = /var/log/uwsgi/usporion.log
#daemonize = /var/log/uwsgi/usporion.log
vacuum = True
max-requests = 1000
processes = 5
threads = 10
workers = 5
vhost = True

Note: I have tried to have daemonize uncommented (but this is not working with current usage).

Lastly, I have this nginx config:

upstream django {
    server 95.168.193.219:80;
}

server {
    listen          95.168.193.219:80;
    server_name     usporion.cz;
    return      301 $scheme://www.usporion.cz$request_uri;
}

server {
    listen          95.168.193.219:80;
    server_name     www.usporion.cz;
    charset         utf-8;

    client_max_body_size 100M;

    location /media {
        alias       /srv/www/usporion/media;
        expires     1d;
    }

    location /static {
        alias       /srv/www/usporion/static;
        expires     1d;
    }

    location / {
        root        /srv/www/usporion;
        include     uwsgi_params;
        uwsgi_pass  unix:///srv/sockets/usporion.sock;
    }
}

Running the command uwsgi --ini /etc/uwsgi/apps-enabled/usporion.ini is working fine and I'm able to see app working on the web. However, if I do service uwsgi start, service is not started (FAIL) with no message and I cannot find anything in the logs. Running this service without usporion.ini in apps-enabled is working fine.

I would be pleased for any help which with I can avoid running uwsgi "service" under screen but run as normal service.

Here is the dist info:

root@[name]:/etc/nginx/sites-enabled# uname -a
Linux [name] 2.6.32-5-amd64 #1 SMP Sun Sep 23 10:07:46 UTC 2012 x86_64 GNU/Linux
root@[name]:/etc/nginx/sites-enabled# cat /etc/debian_version 
6.0.7
root@[name]:/etc/nginx/sites-enabled# nginx -v
nginx version: nginx/1.2.6
root@[name]:/etc/nginx/sites-enabled# uwsgi --version
1.2.3-debian
root@[name]:/etc/nginx/sites-enabled# python --version
Python 2.7.3

Lastly, if someone would like to give me some advice to configure (I'm new to nginx and it's welcome), this is 8-core Xeon server 2.4GHz with 16GB of RAM, half of that is reserved for this app.

like image 324
tomis Avatar asked May 14 '13 21:05

tomis


People also ask

Can I use uWSGI without nginx?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.

What does uWSGI stand for?

uWSGI is an open source software application that "aims at developing a full stack for building hosting services". It is named after the Web Server Gateway Interface (WSGI), which was the first plugin supported by the project. uWSGI is maintained by Italian based software company unbit. uWSGI. Developer(s)

Why do I need uWSGI?

uWSGI is an application server that aims to provide a full stack for developing and deploying web applications and services. Like most application servers, it is language-agnostic but its most popular use is for serving Python applications.


1 Answers

Error is uwsgi configuration:

[uwsgi]
plugins = python
uid = www-data
gid = www-data
uwsgi-socket = /srv/sockets/usporion.sock
chmod-socket = 664
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
wsgi-file = /srv/www/usporion/usporion/wsgi.py
env = DJANGO_SETTINGS_MODULE=usporion.settings
logdate = True
logto = /var/log/uwsgi/usporion.log
#daemonize = /var/log/uwsgi/usporion.log
vacuum = True
max-requests = 1000
master = True
enable-threads = True
processes = 5
threads = 10
vhost = True

Difference is in wsgi-file, what have replaced old module config value. Then, error about missing wsgi file appeared (first written error). daemonize is not necessary here as debian's service is automaticly defined this. Still, I think vacuum, logto is not neccessary there, as well chmod-socket and uwsgi-socket - all of them is defined by debian's service. I will aprove this and complete this answer.

Still, from trying etc., this configuration is basic and everything else should be denifed automaticly or have some default value or by Django itselves:

[uwsgi]
plugins = python
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
wsgi-file = /srv/www/usporion/usporion/wsgi.py
like image 64
tomis Avatar answered Sep 23 '22 02:09

tomis