tomis
tomis

Reputation: 1971

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:

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.

Upvotes: 10

Views: 28665

Answers (1)

tomis
tomis

Reputation: 1971

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

Upvotes: 3

Related Questions