Could not start uwsgi process - python

Could not start uwsgi process via ini flag
uwsgi --ini file.ini
Not any uwsgi pids
ps aux | grep uwsgi
root 31605 0.0 0.3 5732 768 pts/0 S+ 06:46 0:00 grep uwsgi
file.ini
[uwsgi]
chdir =/var/www/lvpp/site
wsgi-file =/var/www/lvpp/lvpp.wsgi
master = true
processes = 1
chmod-socket=664
socket = /var/www/lvpp/lvpp.sock
pidfile= /var/www/lvpp/lvpp.pid
daemonize =/var/www/lvpp/logs/lvpp.log
vacuum = true
uid = www
gid = www
env = DJANGO_SETTINGS_MODULE=settings
file lvpp.log
*** Starting uWSGI 2.0.10 (32bit) on [Wed Apr 8 06:46:15 2015] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 17 March 2015 21:29:09
os: Linux-2.6.32-431.29.2.el6.i686 #1 SMP Tue Sep 9 20:14:52 UTC 2014
machine: i686
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /var/www/lvpp
writing pidfile to /var/www/lvpp/lvpp.pid
detected binary path: /var/www/lvpp/site/env/bin/uwsgi
setgid() to 503
setuid() to 501
chdir() to /var/www/lvpp/site/
your processes number limit is 1812
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)
error removing unix socket, unlink(): Permission denied [core/socket.c line 198]
bind(): Address already in use [core/socket.c line 230]
It worked early.
But when I invoked kill -9 uwsgi.pid I could not start uwsgi process again.
Why can't I start uwsgi process again?

The key is:
error removing unix socket, unlink(): Permission denied [core/socket.c line 198]
You (very probably) previously run a uwsgi instance as root creating the unix socket file with root permissions.
Now your instance (running instead as www) is not able to re-bind() that socket as it is not able to unlink it (no permissions)
Just remove the socket file and retry.

I was running into a very similar issue, except it still wouldn't work even after deleting the socket file. Turns out it was because uWSGI couldn't create a new one (it only existed because I ran uwsgi myself). The infuriatingly simple solution was to chmod the directory containing the socket file, allowing the www user to create and modify files there. Obvious now, but maybe this will help a future poor sap bashing their head against a wall, as I have been for too many hours today.
root#srv16:/var/run/uwsgi> ls -la
total 0
drwxr-xr-x 2 root root 60 Jul 16 07:11 . #<-- problem
drwxr-xr-x 25 root root 880 Jul 19 09:14 ..
srw-rw---- 1 www-app www-data 0 Jul 16 07:11 app.socket
#^-- no idea how www-app managed to create that file
root#simsrv16:/var/run/uwsgi> chmod 777 . #<-- fix

Beyond the main socket there could be also a stats socket. :)
The error log actually could be more specific abouth the path that isn't mentioned.

Related

Getting chown(): Operation not permitted while running uwsgi from ini file

I am trying to run nginx and uwsgi.
When I try to run uwsgi with below command in my proj virtual environment with proj user I get an error. When I run uwsgi, I see the proj.sock is created in /run/uwsgi/proj.sock
I changed the /run/uwsgi permissions to drwxrwxrwx to see if the problem is permission related. But problem still appears. I also checked the /etc/passwd and there is no uwsgi user.
The directory info for /run/uwsgi is :
drwxrwxrwx 2 root root 60 Jul 16 10:53 uwsgi
When I try to change ownership of sock file with proj user to proj:nginx in proj virtual nvironment I get the error below.
chown: changing ownership of ‘/run/uwsgi/proj.sock’: Operation not permitted
When I check /run/uwsgi/proj.sock file it is proj:proj but it should be changed to proj:nginx. This operation can be done manually with root. But it cannot be done with proj user.
Run below command:
uwsgi --ini /etc/uwsgi/sites/proj.ini
Error :
[uWSGI] getting INI configuration from /etc/uwsgi/sites/proj.ini<br>
*** Starting uWSGI 2.0.15 (64bit) on [Mon Jul 16 10:53:02 2018] ***<br>
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-28) on 13 July 2018 17:12:50<br>
os: Linux-3.10.0-862.6.3.el7.x86_64 #1 SMP Tue Jun 26 16:32:21 UTC 2018<br>
nodename: localhost.localdomain<br>
machine: x86_64<br>
clock source: unix<br>
detected number of CPU cores: 2<br>
current working directory: /home/proj<br>
detected binary path: /home/proj/Env/proj/bin/uwsgi<br>
!!! no internal routing support, rebuild with pcre support !!!<br>
chdir() to /home/proj/work/proj<br>
your processes number limit is 4096<br>
your memory page size is 4096 bytes<br>
detected max file descriptor number: 1024<br>
lock engine: pthread robust mutexes<br>
thunder lock: disabled (you can enable it with --thunder-lock)<br>
chown(): Operation not permitted [core/utils.c line 2623]<br>
VACUUM WARNING: unix socket /run/uwsgi/proj.sock changed inode. Skip removal
My proj.ini file for uwsgi ini configuration is :
[uwsgi]
py-autoreload = 2
project = proj
username = proj
base = /home/%(username)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = %k
uid = %(username)
socket = /run/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 666
vacuum = true
#logto = /var/log/uwsgi/%(project).log
A user can only set the group of a file to a group he is in. In this case your user proj is not in the nginx group, so it is not allowed to make that change. If you add the user to the nginx group (and relogin) then it should work.
Also, setting the directory permissions to 777 allows any user to create and delete files in that directory, and 666 for the socket allows any user to access it. You probably don't want that. More reasonable would be to have /run/uwsgi owned by root:nginx with mode 770, and chmod-socket = 660 in your project ini.
I solved the problem.
The socket files were in /run/uwsgi directory.
I gave the related project user right to write read execute on this folder.
setfacl -m u:projuser:rwx /run/uwsgi/
As suggested by "ivbtar", I just removed following lines from uwsgi.ini file and it started working,
chown-socket = %(username):nginx
chmod-socket = 666

Serving files in directory to uWSGI Flask apps run with Emperor

I changed my uWSGI setup to use the Emperor for multi-app deployment. With the old setup when loading 'mypasswords.pwds' file which was saved right next to my app, there was no issue.
Now running everything with the Emperor I get 'No such file or direcotry' errors. This might be because of my setup or because the Emperor simply works in a different way and I'm not sure what's the case.
Directory Tree:
Project
thisismyapp.py
passwords.pwds
Config for uWSGI Emperor:
[uwsgi]
# Variables
base = /var/www/Project
# Generic Config
home = %(base)/venv
pythonpath = %(base)
socket = /tmp/%n.sock
module = thisismyapp:app # Is this an issue?
logto = /var/log/uwsgi/%n.log
Traceback:
*** Starting uWSGI 2.0.11.2 (64bit) on [Thu Feb 4 00:41:47 2016] ***
compiled with version: 4.9.2 on 24 October 2015 23:42:32
os: Linux-3.19.0-42-generic #48-Ubuntu SMP Thu Dec 17 22:54:45 UTC 2015
nodename: website
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/apps-enabled
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 1868
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)
uwsgi socket 0 bound to UNIX address /tmp/project.sock fd 3
Python version: 2.7.9 (default, Apr 2 2015, 15:37:21) [GCC 4.9.2]
Set PythonHome to /var/www/Project/venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x17355e0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/Project/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x17355e0 pid: 6772 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 6772)
spawned uWSGI worker 1 (pid: 6779, cores: 1)
[pid: 6779|app: 0|req: 1/1] 79.227.145.119 () {46 vars in 967 bytes} [Thu Feb 4 00:41:51 2016] GET / => generated 3552 bytes in 355 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)
announcing my loyalty to the Emperor...
[Errno 2] No such file or directory: 'passwords.pwds'
Python file access:
f = open('passwords.pwds', 'r')
Try this one:
from os import path
passwords_location = path.join(path.dirname(path.realpath(__file__), 'passwords.pwds'))
with open(passwords_location) as f:
do_something()
Your original way using the relative location, so may can't find the file if you're not in the Project folder. Also, use with block is a better way to handle files, it will ensure to close the file when exit the context block.

UWSGI not running Django project

I am trying to run this code
uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data
I am following this tutorial. But I am getting the below output.
*** Starting uWSGI 2.0.11.2 (64bit) on [Thu Nov 5 04:42:12 2015] ***
compiled with version: 4.8.4 on 04 November 2015 16:32:43
os: Linux-3.16.0-52-generic #71~14.04.1-Ubuntu SMP Fri Oct 23 17:24:53 UTC 2015
nodename: myproject
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /var/www/myproject
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
setgid() to 33
setuid() to 33
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 15305
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
This is my .ini file
plugins = python
chdir = /var/www/myproject/
module = myproject.wsgi:application
home = /var/www/
master = true
processes = 10
socket = /var/www/myproject/uwsgi.sock
chmod-socket = 666
vacuum = true
My code is working with this
uwsgi --ini myproject.ini
Please help me to solve this puzzle thank you.
It seems to work fine! Did you try connecting nginx? You can ignore the warnings now.

Flask Server: ImportError: No module named site

I'm trying to run a Flask application using a ubuntu 12.04 server with nginx and uWSGI however after starting the server, specifying the wsgi.ini file and then starting nginx, I try to access the page but I get a 502 bad gateway error with nginx. I know that it is an issue with the flask application and uWSGI. I checked the uWSGI logs and found this:
*** Starting uWSGI 2.0.11.1 (64bit) on [Thu Sep 17 19:38:03 2015] ***
compiled with version: 4.8.4 on 17 September 2015 15:58:04
os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
nodename: ip-172-31-30-153
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/myapp
writing pidfile to /home/ubuntu/myapp/myapp.pid
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7862
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)
uwsgi socket 0 bound to TCP address 127.0.0.1:5000 fd 3
Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2]
Set PythonHome to /home/ubuntu/myapp
ImportError: No module named site
I found this question's top answer but saw received the same error. If it is something to do with PYTHONHOME, I'm following this guide and it states:
The $PYTHONPATH variable seems to get unset randomly, and causes
errors for later steps. To avoid this, add the following line to the
top of your ~/.bashrc file:
export
PYTHONPATH='/usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages/PILcompat'
So what could be the issue? Is it PYTHONHOME or another factor affecting it? Thanks.
Edit:
My uwsgi.ini:
[uwsgi]
home = /home/ubuntu/myapp
wsgi-file = %(home)/run.py
socket = 127.0.0.1:5000
callable = app
module = app
pythonpath = %(home)
daemonize = %(home)/myapp.log
pidfile = %(home)/myapp.pid
To run it, I use uwsgi uwsgi.ini.

Setting up Unix Socket with Nginx and Django

I'm trying to follow the tutorial at http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html. I've gotten everything working down to http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#using-unix-sockets-instead-of-ports. I am working with an ubuntu 14.4 instance on amazon EC2:
The Nginx config file starts with:
# the upstream component nginx needs to connect to
upstream django {
server unix:///path/to/your/mysite/mysite.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
I am confused about the syntax of setting up a unix socket. I've looked at several sources including http://pymotw.com/2/socket/uds.html , Permission denied - nginx and uwsgi socket and https://serverfault.com/questions/124517/whats-the-difference-between-unix-socket-and-tcp-ip-socket
It looks like they all start with "///" If I understand correctly the path just points to the root directory of ( in my case ) the django project and the path has to end with ".sock" . Does this seem right ?
edit: I've made the uwsgi config file, but I'm trying to run this with the --socket switch instead:
The Nginx config file now starts with:
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/mysite.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
Following what I think you are saying, I'm running uwsgi on socket /tmp/mysite.sock .
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --socket /tmp/mysite.sock --wsgi-file test.py --chmod-socket=664
When I open:
http://52.10.----:8000/
In firefox I see:
502 Bad Gateway
The error log for nginx shows:
2015/03/04 15:08:44 [crit] 18398#0: *3 connect() to unix:///home/ubuntu/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///home/ubuntu/mysite.sock:", host: "52.10.200.38:8000"
edit 2: I commented out the django related stuff -
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
#chdir = /path/to/your/project
# Django's wsgi file
#module = project.wsgi
# the virtualenv (full path)
#home = /path/to/virtualenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 1
# the socket (use the full path to be safe
socket = /tmp/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
# clear environment on exit
vacuum = true
I tried:
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file test.py
but got a 502 error again.
2015/03/04 17:50:00 [crit] 18842#0: *1 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.200.38:8000"
EDIT 3:
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file te
st.py
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 18:41:43 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-28-196
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 7862
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)
uwsgi socket 0 bound to UNIX address /tmp/mysite.sock fd 3
Python version: 3.4.0 (default, Apr 11 2014, 13:08:40) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x205e710
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x205e710 pid: 18868 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 18868)
spawned uWSGI worker 1 (pid: 18869, cores: 1)
edit 4: - just noticed
♥SIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
goodbye to uWSGI.
VACUUM: unix socket /tmp/mysite.sock removed.
So everytime I exit uWSGI, the socket is being removed. Maybe I should turn the vaccum option off so the chmod settings are preserved?
I changed:
vacuum = false
but...
(env1)ubuntu#ip-172-31-28-196:/tmp$ sudo chmod 777 mysite.sock
(env1)ubuntu#ip-172-31-28-196:/tmp$ ls -la
total 8
drwxrwxrwt 2 root root 4096 Mar 4 19:32 .
drwxr-xr-x 22 root root 4096 Mar 4 19:06 ..
srwxrwxrwx 1 ubuntu ubuntu 0 Mar 4 19:32 mysite.sock
(env1)ubuntu#ip-172-31-28-196:/tmp$ cd /home/ubuntu/
(env1)ubuntu#ip-172-31-28-196:~$ ls
host_type.py requirements.txt test.py tproxy
(env1)ubuntu#ip-172-31-28-196:~$ sudo /etc/init.d/nginx restart
* Restarting nginx nginx
...done.
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-fi
st.py
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 19:36:42 2015] ***
.....
spawned uWSGI worker 1 (pid: 1568, cores: 1)
♥SIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
goodbye to uWSGI.
(env1)ubuntu#ip-172-31-28-196:~$ cd /tmp
(env1)ubuntu#ip-172-31-28-196:/tmp$ ls -la
total 8
drwxrwxrwt 2 root root 4096 Mar 4 19:36 .
drwxr-xr-x 22 root root 4096 Mar 4 19:06 ..
srw-rw-r-- 1 ubuntu ubuntu 0 Mar 4 19:36 mysite.sock
so chmod is not preserved..
edit 5:
(env1)ubuntu#ip-172-31-28-196:/tmp$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini --wsgi-file
test.py --chmod-socket=777
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Wed Mar 4 20:54:21 2015] ***
compiled with version: 4.8.2 on 03 March 2015 02:58:28
os: Linux-3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014
nodename: ip-172-31-28-196
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /tmp
detected binary path: /home/ubuntu/.virtualenvs/env1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 7862
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)
uwsgi socket 0 bound to UNIX address /tmp/mysite.sock fd 3
Python version: 3.4.0 (default, Apr 11 2014, 13:08:40) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x18b4790
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
failed to open python file test.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1858)
spawned uWSGI worker 1 (pid: 1859, cores: 1)
--- no python application found, check your startup logs for errors ---
[pid: 1859|app: -1|req: -1/1] 64.56.60.130 () {36 vars in 555 bytes} [Wed Mar 4 20:54:34 2015] GET
/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
Now getting internal server error:
2015/03/04 19:33:26 [crit] 1531#0: *1 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 64.56.60.130, server: 52.10.200.38, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.200.38:8000"
Change it to say server unix:///tmp/mysite.sock; and then in the uwsgi ini file you make, create the unix socket in /tmp/

Categories