uwsgi emperor mod not working - python

when i start it without emperor it works:
uwsgi --ini /etc/uwsgi/vassals/uwsgi.conf --uid books --gid books
But when i use emperor mode it freezes:
uwsgi --emperor /etc/uwsgi/vassals --uid books --gid books
And give such response:
*** Starting uWSGI 2.0.1 (64bit) on [Fri Oct 24 10:47:46 2014] ***
compiled with version: 4.8.2 20140120 (Red Hat 4.8.2-16) on 24 October 2014 10:36:47
os: Linux-3.10.0-123.8.1.el7.x86_64 #1 SMP Mon Sep 22 19:06:58 UTC 2014
nodename: essenly.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/bin/uwsgi
setgid() to 1000
setuid() to 1000
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3839
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
Thanks for your help.

UPDATE. Ignore my advice regarding master. Doc says that emperor mode should not be used with master normally. http://uwsgi-docs.readthedocs.org/en/latest/Emperor.html#notes
Try to run emperor with master process. Add master = true to your ini file and run uwsgi as root. Workers will downgrade to non-priviledged user (if specified)

Related

uwsgi Exception: not correct domain name /

I have some application written in python.
I'm trying to run python application under uwsgi.
My app.ini:
[uwsgi]
chdir = /var/www/myapp
wsgi-file = /var/www/myapp/app.wsgi
uid = apache
gid = apache
master = true
processes = 1
socket = :8080
vacuum = true
Start uwsgi:
uwsgi --ini app.ini
[uWSGI] getting INI configuration from app.ini
*** Starting uWSGI 2.0.10 (64bit) on [Sat Mar 21 16:59:09 2015] ***
compiled with version: 4.8.2 20140120 (Red Hat 4.8.2-16) on 21 March 2015 16:55:47
os: Linux-3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014
nodename: lw_site
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /var/www/myapp
detected binary path: /usr/bin/uwsgi
chdir() to /var/www/myapp
your processes number limit is 4096
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 :8080 fd 3
Python version: 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x2644f70
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 0x2644f70 pid: 39838 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 39838)
spawned uWSGI worker 1 (pid: 39839, cores: 1)
This is
WSGI app 0 (mountpoint='')
confuse me.
I get this error:
Custom Error: Traceback (most recent call last):
File "/var/www/myapp/app/manager.py", line 53, in app
contrller, args = router.mapping(request, city_model)
File "/var/www/myapp/app/router.py", line 478, in mapping
raise Exception('not correct domain name '+str(rurl))
Exception: not correct domain name /
Where is I made a mistake ?
I have found the error. It's problem in code. It get domain name from SERVER_NAME variable. I set in nginx:
uwsgi_param SERVER_NAME $host;

502 Bad Gateway connecting Nginx to django via socket

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#running-the-django-application-with-uwsgi-and-nginx. I am working with an ubuntu 14.4 instance on amazon EC2:
My django project is called tp. Here's a screenshot:
Following the instructions I have done:
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --socket /tmp/mysite.sock --module /home/ubuntu/tproxy/tp/tp
/wsgi.py --chmod-socket=664
*** Starting uWSGI 2.0.9 (64bit) on [Thu Mar 5 16:50:02 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 !!!
*** 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 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 0x1fe5320
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named '/home/ubuntu/tproxy/tp/tp/wsgi'
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 worker 1 (and the only) (pid: 24393, cores: 1)
Obviously you can see:
ImportError: No module named '/home/ubuntu/tproxy/tp/tp/wsgi'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
How do I set the path to the wsgi.py file?
edit 1: here's my ini file:
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/ubuntu/tproxy/tp
# Django's wsgi file
module = uwsgi
# the virtualenv (full path)
home = /home/ubuntu/.virtualenvs/env1
wsgi-file = /home/ubuntu/tproxy/tp/tp/wsgi.py
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 3
# 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 ran:
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
but still getting a 502 error.
Logs:
2015/03/05 18:10:00 [crit] 1828#0: *51 connect() to unix:///tmp/mysite.sock failed (13: Permission denied) while connecting to upstream, client: 107.0.193.131, server: 52.10.**-**, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.sock:", host: "52.10.**-**:8000"
edit 2 : is home the directory for virtualenv? I set:
home = /home/ubuntu/tproxy/
Now:
(env1)ubuntu#ip-172-31-28-196:~$ uwsgi --ini /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
[uWSGI] getting INI configuration from /home/ubuntu/tproxy/tp/mysite_uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Thu Mar 5 18:59:27 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 !!!
chdir() to /home/ubuntu/tproxy/tp
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]
Set PythonHome to /home/ubuntu/tproxy/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Aborted (core dumped)
You put it in your uwsgi ini file. Here is an example one:
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /var/www/virtualenv/project
# Django's wsgi file
module = uwsgi
# the virtualenv (full path)
home = /var/www/virtualenv/
wsgi-file = /var/www/virtualenv/project/projectsettings/wsgi.py
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# 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
This is my ini file minus my path's to my projects. I also ran into this same issue when installing it myself but was able find the appropriate answer from looking at other configs on google.

Uwsgi: "Cannot assign requested address"

So I have a django project all set and ready to go, and then I attempted to start it using uwsgi via this command
# uwsgi --http :5000 --module myProject.wsgi
This then returns this error log
** Starting uWSGI 2.0.3 (32bit) on [Sun Apr 13 14:23:55 2014] ***
compiled with version: 4.6.3 on 13 April 2014 14:06:52
os: Linux-2.6.32-042stab078.26 #1 SMP Wed Jun 19 11:05:34 MSK 2013
nodename: vps
machine: i686
clock source: unix
detected number of CPU cores: 1
current working directory: /root/HomeworkTasker
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 191584
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)
bind(): Cannot assign requested address [core/socket.c line 759]
After some googling it seems it has been said that this address is already in use, I have determined this is not the case for multiple reasons. The first of these reasons is that if I go into a python shell, I can bind 0.0.0.0:5000 manually with python. The other reason is that if I go netstat, port 5000 is NOT listed. Anything I can do here or am I SOL?
Solution Found:
Make sure your interfaces are correct by running
ifconfig lo up

Use virtualenv owned by root in a python web project on production

So I have the following configuration:
Nginx server with uWsgi
Django project in a virtualenv
My virtualenv is owned by an ordinal system user and the whole configuration works fine!
The uwsgi process is configured to run with nginx uid & gid, as well as the nginx process owner in the nginx.conf.
But, if I try to use another virtualenv satisfying the same requirements, but owned by root, my uwsgi can't locate the virtualenv, throwing an import error.
Is this normal and is my aproach correct to use a root owned virtualenv?
Edit:
uwsgi config:
[uwsgi]
virtualenv = /root/Envs/rootenv
thread = 4
uid = nginx
gid = nginx
env = DJANGO_SETTINGS_MODULE=myServer.settings
module = django.core.handlers.wsgi:WSGIHandler()
chdir = /var/www/myServer
socket = /var/run/uwsgi/myserver.sock
logto = /var/log/uwsgi/myserver.log
/root/.bashrc:
### Virtualenv settings ###
export WORKON_HOME=/root/Envs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
uwsgi log traceback:
*** Starting uWSGI 1.9.15 (64bit) on [Fri Sep 6 14:02:41 2013] ***
compiled with version: 4.7.2 on 06 September 2013 10:59:26
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
nodename: myserver3
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /
detected binary path: /usr/local/bin/uwsgi
setgid() to 32
set additional group 4 (adm)
setuid() to 32
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7929
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
Python version: 2.7.3 (default, Jan 2 2013, 14:09:21) [GCC 4.7.2]
Set PythonHome to /root/Envs/rootenv
ImportError: No module named site
*** Starting uWSGI 1.9.15 (64bit) on [Fri Sep 6 14:03:13 2013] ***
compiled with version: 4.7.2 on 06 September 2013 10:59:26
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
nodename: myserver3
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /
detected binary path: /usr/local/bin/uwsgi
setgid() to 32
set additional group 4 (adm)
setuid() to 32
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7929
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
Python version: 2.7.3 (default, Jan 2 2013, 14:09:21) [GCC 4.7.2]
Set PythonHome to /root/Envs/rootenv
ImportError: No module named site

switch python version on uwsgi

I am running a django app with nginx and uwsgi. It was was working ok but suddenly I do not know what I changed that the app stop working.
The problem resides in that python version from uWsgi is 2.4.3 which is the default version in Linux CentOs and I have installed django, webpy and other python distributions in version 2.7.3 (will upgrade sooner)
I also tried creating a symbolic link from python 2.7 path to just "python" in usr/bin
and did not work.
How can I make uWsgi use python2.7.3(/usr/local/bin/) instead of 2.4.3?
Django ini:
socket = 127.0.0.1:3031
master = true
processes = 4
env = DJANGO_SETTINGS_MODULE=djtest.settings
module = django.core.handlers.wsgi:WSGIHandler()
When I initialize
./uwsgi --ini django.ini
[uWSGI] getting INI configuration from django.ini
*** Starting uWSGI 1.3 (64bit) on [Sat Nov 24 00:27:55 2012] ***
compiled with version: 4.1.2 20080704 (Red Hat 4.1.2-52) on 23 November 2012 22:37:39
os: Linux-2.6.18-194.17.4.el5xen #1 SMP Mon Oct 25 16:36:31 EDT 2010
nodename: v238545.hostingator.net
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /root
detected binary path: /opt/uwsgi/uwsgi
your processes number limit is 32832
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 5841)
uwsgi socket 0 bound to TCP address 127.0.0.1:59395 (port auto-assigned) fd 3
Python version: 2.4.3 (#1, Jun 18 2012, 08:55:23) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1cc1130
your server socket listen backlog is limited to 100 connections
mapped 72352 bytes (70 KB) for 1 cores
*** Operational MODE: single process ***
added /usr/local/bin/ to pythonpath.
added /home/indaxone/serv/ to pythonpath.
ImportError: No module named django.core.handlers.wsgi
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 worker 1 (and the only) (pid: 5840, cores: 1)
Before doing the "make" during the uwsgi installation I did the following:
python2.7 uwsgiconfig.py --build

Categories

Resources