Lucas03
Lucas03

Reputation: 2347

cant run uwsgi with ini file in emperror mode - Permission denied

I cant run uwsgi in emperror mode with my ini file. I have installed uwsgi with sudo pip install uwsgi.
When I try to start uwsgi, I get error:

sudo /etc/init.d/uwsgi start
/etc/init.d/uwsgi: line 72: /usr/share/uwsgi/init/snippets: No such file or directory
/etc/init.d/uwsgi: line 73: /usr/share/uwsgi/init/do_command: No such file or directory
[....] Starting app server(s): uwsgi/etc/init.d/uwsgi: line 80: do_command: command not found
 failed!

I'm using Debian. Firstly I tried to follow django and nginx docs, but when it did not work I googled a lot. This is my ebook_uwsgi.ini file:

# ebook_uwsgi.ini file
[uwsgi]
emperor = /etc/uwsgi/vassals
#plugins        = python #if uwsgi installed with pip, dont have to use this line
# Django-related settings
# the base directory (full path)
chdir           = /var/www/django/ebook/ebook/wsgi/ebook/
# Django's wsgi file
module          = controller.wsgi:application
# the virtualenv (full path)
home            = /var/www/django/ebook

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10

# the socket (use the full path to be safe
socket         = /var/uwsgi/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
uid             = www-data
gid             = www-data
# clear environment on exit
vacuum          = true


no-site         = True
wsgi-file       = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
env             = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable

And here is my ebook_nginx.conf:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///var/uwsgi/ebook.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8001;
    # the domain name it will serve for
    server_name IP #.bookdownloading.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /var/www/django/ebook/ebook/data;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        include     /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
    }
}

Where IP stands for servers real IP. When I start uwgi with my ini file I get Permission denied:

uwsgi --ini ebook_uwsgi.ini 
[uWSGI] getting INI configuration from ebook_uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Tue Apr 14 17:11:32 2015] ***
compiled with version: 4.7.2 on 14 April 2015 16:47:40
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /var/www/django/ebook/ebook
detected binary path: /usr/local/bin/uwsgi
chdir() to /var/www/django/ebook/ebook/wsgi/ebook/
your processes number limit is 2062113
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
*** starting uWSGI Emperor ***
bind(): Permission denied [core/socket.c line 230]

I am using socked in /var/uwsgi/ebook.sock where I have set www-data as owner of uwsgi directory:

ls -la /var
total 128
drwxr-xr-x 13 root     root     15 apr 14 16:29 .
drwxr-xr-x 23 root     root     23 apr 12 19:46 ..
drwxr-xr-x  2 root     root     19 apr 13 06:25 backups
...
drwxr-xr-x  2 www-data www-data  2 apr 14 16:36 uwsgi

Why do I get Permission denied?
//EDIT: I was missing some config settings. So here is my new ini file:

# ebook_uwsgi.ini file
[uwsgi]
#emperor = /etc/uwsgi/vassals
#plugins        = python #if uwsgi installed with pip, dont have to use this line
# Django-related settings
# the base directory (full path)
chdir           = /var/www/django/ebook/ebook/wsgi/ebook/
# Django's wsgi file
module          = controller.wsgi:application
# the virtualenv (full path)
home            = /var/www/django/ebook

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 1

# the socket (use the full path to be safe
socket         = /var/uwsgi/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664
uid             = www-data
gid             = www-data
# clear environment on exit
vacuum          = true


no-site         = True
wsgi-file       = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
#env             = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable

and nginx settings:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream ebook {
    server unix:///var/uwsgi/ebook.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8001 default_server;
    # the domain name it will serve for
    server_name IP; #.bookdownloading.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /var/www/django/ebook/ebook/data;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass      ebook;
        include         /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
    }
}

No matter if I run uwsgi or not, I get 502 Bad Gateway. Error nginx log:

2015/05/12 16:22:08 [crit] 3002#0: *1 connect() to unix:///var/uwsgi/ebook.sock failed (13: Permission denied) while connecting to upstream, client: 78.45.37.119, server: IP, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///var/uwsgi/ebook.sock:", host: "IP:8001"

Hm, even though I have set owner of stocket file to www-data, it was created as my user and nginx could not read it.

Upvotes: 4

Views: 6695

Answers (3)

diveinsky
diveinsky

Reputation: 165

I too faced the same.

/usr/share/uwsgi/init/snippets and /usr/share/uwsgi/init/do_commands

Above two files are missing with pip install uwsgi

But apt-get install uwsgi adds above two files and resolves issue

Upvotes: 1

Lucas03
Lucas03

Reputation: 2347

Somehow, when I run uwsgi from my linux user, uwsgi ignored my ini file and created ebook.sock with owner and group of my user, not specified www-data. When I changed owner and group manually to www-data, web loaded.
Problem was with permissions for file uwsgi_params. After using nginx file it worked all right.

Upvotes: 0

AlvaroAV
AlvaroAV

Reputation: 10563

I've read your post and you're getting the permission issue because maybe www-data don't have write permissions on the folder uwsgi, you have two ways of testing it:

  1. Log in with the www-data user and try to create a file inside /var/uwsgi/
    • To log in with www-data user su - www-data
  2. Change the folder permissions to 775 (chmod 775 /var/uwsgi/)

Another option could be try to change the path of the sockets to the tmp folder. I tried your configuration in a VM using tmp folder and it works perfectly

ebook_uwsgi.ini:

socket = /tmp/ebook.sock

ebook_nginx.conf:

upstream django {
    server unix:///tmp/ebook.sock;
}

Upvotes: 5

Related Questions