I am having trouble getting my flask app to run on a new server running CentOS 6.5.using uWSGI. (I have a similar CentOS box that it runs fine on)
I installed uWSGI within a virtual environment. I was getting the following error (in stdout) when calling uwsgi binary from the virtualenv
$ /path/to/venv/bin/uwsgi --emperor /etc/uwsgi/vassals
*** Starting uWSGI 2.0.8 (64bit) on [Mon Nov 17 21:18:13 2014] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 16 November 2014 22:19:09
os: Linux-2.6.32-431.1.2.0.1.el6.x86_64 #1 SMP Fri Dec 13 13:06:13 UTC 2013
nodename: boxname
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/username
detected binary path: /home/username/mydevelopment/venvs/ecodev_do/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 1024
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from ers_portal_uwsgi.ini
Mon Nov 17 21:18:14 2014 - [emperor] curse the uwsgi instance ers_portal_uwsgi.ini (pid: 22724)
Mon Nov 17 21:18:17 2014 - [emperor] removed uwsgi instance ers_portal_uwsgi.ini
The uwsgi.log file shows:
*** Starting uWSGI 2.0.8 (64bit) on [Mon Nov 17 21:25:40 2014] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-11) on 16 November 2014 22:19:09
os: Linux-2.6.32-431.1.2.0.1.el6.x86_64 #1 SMP Fri Dec 13 13:06:13 UTC 2013
nodename: boxname
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /home/username/mydevelopment/venvs/ecodev_do/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/username/mydevelopment/git/ers_portal
your processes number limit is 1024
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 /home/username/mydevelopment/git/ers_portal/ers_portal_uwsgi.sock fd 3
Python version: 2.7.8 (default, Nov 12 2014, 23:36:57) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]
Set PythonHome to /home/username/mydevelopment/venvs/ecovapor_dev
ImportError: No module named site
Then, reading the official uWSGI documentation they describe a scenario where uwsgi is installed in a venv, but then it has to be installed system-wide after that. So, I used
pip2.7 install uwsgi (which created the binary in /usr/local/bin/uwsgi)
I have tried all of the following with no change in the error or the output (with and without venv activated)..
$ /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals
$ /home/username/mydevelopment/venvs/ecodev_do/bin/uwsgi --emperor /etc/uwsgi/vassals
$ /home/username/mydevelopment/venvs/ecodev_do/bin/uwsgi --no-site
--emperor /etc/uwsgi/vassals
$ uwsgi --emperor /etc/uwsgi/vassals
$ uwsgi --no-site --emperor /etc/uwsgi/vassals
$ /path/to/venv/bin/uwsgi ~/mydevelopment/git/ers_portal/ers_portal_uwsgi.ini (the .ini file is symlinked in /etc/uwsgi/vassals )
Here is emperor.ini;
[uwsgi]
emperor = /etc/uwsgi/vassals
uid = username
gid = username
logto = /home/username/mydevelopment/git/ers_portal/logs/uwsgiEmperor.log
Here is ers_portal_uwsgi.ini;
[uwsgi]
master = true
#user info
uid = username
gid = username
#application's base folder
base = /home/username/mydevelopment/git/ers_portal
#chdir to this folder when starting
chdir = /home/username/mydevelopment/git/ers_portal
#python module to import
app = run_web
module = %(app)
home = /home/username/mydevelopment/venvs/ecovapor_dev
pythonpath = %(base)
#socket file's location
socket = /home/username/mydevelopment/git/ers_portal/%n.sock
#permissions for the socket file
chmod-socket = 666
#the variable that holds a flask application inside the module imported at line #6
#uwsgi varible only, does not relate to your flask application
callable = app
#location of log files
logto = /home/username/mydevelopment/git/ers_portal/logs/%n.log
This helped me.
Type it in your terminal.
unset PYTHONHOME
unset PYTHONPATH
In case someone uses python 3.x, installing uwsgi with pip3 solved this problem for me:
sudo pip3 install uwsgi
The virtualenv in question and uwsgi must be using the same python version.
In case you want to use multiple python versions on the same system, you can get the uwsgi source and follow the instructions here: http://projects.unbit.it/uwsgi/wiki/MultiPython
Then add a "plugin=/path/to/plugin" to the .ini file
Take note that plugins dont work for the packaged Ubuntu versions (built monolithic), but you need to compile the source directly for a fully modular binary
Related
I have hosted a webapp on a linux server using django-uwsgi,I was trying to directly call the --ini file from uwsgi as uwsgi --ini .ini file but I'm getting a weird error like this.
[uWSGI] getting INI configuration from /etc/uwsgi/sites/salesproject.ini
*** Starting uWSGI 2.0.18 (64bit) on [Tue May 19 23:37:24 2020] ***
compiled with version: 9.3.0 on 18 May 2020 16:02:04
os: Linux-5.4.0-26-generic #30-Ubuntu SMP Mon Apr 20 16:58:30 UTC 2020
nodename: django-server
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /var/uwsgi
detected binary path: /home/ubaid/.local/bin/uwsgi
chdir() to /home/ubaid/salesproject
your processes number limit is 15402
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 /var/uwsgi/salesproject.sock fd 3
Python version: 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
!!! Python Home is not a directory: /home/ubaid/Env/salesproject !!!
Set PythonHome to /home/ubaid/Env/salesproject
Python path configuration:
PYTHONHOME = '/home/ubaid/Env/salesproject'
PYTHONPATH = (not set)
program name = '/home/ubaid/Env/salesproject/bin/python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/home/ubaid/Env/salesproject/bin/python'
sys.base_prefix = '/home/ubaid/Env/salesproject'
sys.base_exec_prefix = '/home/ubaid/Env/salesproject'
sys.executable = '/home/ubaid/Env/salesproject/bin/python'
sys.prefix = '/home/ubaid/Env/salesproject'
sys.exec_prefix = '/home/ubaid/Env/salesproject'
sys.path = [
'/home/ubaid/Env/salesproject/lib/python38.zip',
'/home/ubaid/Env/salesproject/lib/python3.8',
'/home/ubaid/Env/salesproject/lib/python3.8/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f966c94e680 (most recent call first):
<no Python frame>
VACUUM: unix socket /var/uwsgi/salesproject.sock removed.
Salesproject is my webapp and I definetly don't have a path like this /home/ubaid/Env/salesproject,
my path is like this /home/ubaid/salesproject,
Can you please help me resolve this? And yeah I have python3 installed
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.
I'm not able to run uwsgi with upstart/supervisord, I used pyenv to setup python with virtualenv myenv, myenv has python3.4.3 and system's python pointing to python2.7.6. I changed pyenv global to 3.4.3.
Right now as my_user, which python => /home/my_user/.pyenv/shims/python and python --version => Python 3.4.3.
When I do with sudo, I get sudo which python => /usr/bin/python and sudo python --version => Python 2.7.6.
/etc/init/uwsgi_servers.conf has
description "uWSGI instance to serve authservice in production"
start on runlevel [2345]
stop on runlevel [!2345]
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites/ --uid my_user --gid my_user
and /etc/uwsgi/sites/uwsgi.ini has
[uwsgi]
# variables
projectname = accounts
base = /home/my_user/django/accounts/
for-readline = /home/my_user/conf/django/accounts/env_var
env = %(_)
endfor =
# config
chdir = /home/my_user/django/accounts/
master = True
processes = 5
protocol = uwsgi
env = in_accounts.settings.production
module = in_accounts.wsgi
socket = /tmp/uwsgi_%(projectname).sock
chmod-socket = 666
home = /home/my_user/.virtualenvs/accounts_production
logto = %(base)/logs/uwsgi.log
daemonize = /var/log/uwsgi/%(projectname).log
vacuum = True
pidfile = /tmp/%(projectname).pid
die-on-term = true
When I run sudo service uwsgi_servers start, I get error from log
*** Starting uWSGI 2.0.11.2 (64bit) on [Tue Oct 13 09:32:18 2015] ***
compiled with version: 4.8.4 on 12 October 2015 11:59:31
os: Linux-3.16.0-43-generic #58~14.04.1-Ubuntu SMP Mon Jun 22 10:21:20 UTC 2015
nodename: st-auths-web1
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/sites
writing pidfile to /tmp/accounts.pid
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /home/my_user/django/accounts/current
your processes number limit is 13731
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/uwsgi_accounts.sock fd 3
Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2]
Set PythonHome to /home/my_user/.virtualenvs/accounts_production
ImportError: No module named site
VACUUM: pidfile removed.
VACUUM: unix socket /tmp/uwsgi_accounts.sock removed.
From log I can see that starting uwsgi using upstart try to use python2.7.6 since I use sudo to run upstart service, but It should have used python3.4.3, this might be the reason why server isn't running. Though I use uid and gid I get the above error. I also tried setuid and setgid, but no luck.
NOTE: I can able to run uwsgi server successfully without upstart as uwsgi --emperor /etc/uwsgi/sites/. I tried use supervisord, but no use, getting same error.
To make this work you will have to tell wsgi which virtualenv to use that's with the -H option. If your virtualenv is in your home folder, upstart will not be able to access it. So move it to a readable place and try
uwsgi -H /usr/local/virtualenv
or something like that with the correct path to the virtualenv in your upstart file.
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.
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 tohttp://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#install-uwsgi-system-wide. I am working with an ubuntu 14.4 instance on amazon EC2:
Without going into my virtualenv , I ran:
sudo pip install uwsgi
This led to
############## end of uWSGI configuration #############
total build time: 24 seconds
*** uWSGI is ready, launch it with /usr/local/bin/uwsgi ***
Successfully installed uwsgi
Cleaning up...
Then I ran:
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 [Fri Mar 6 16:15:07 2015] ***
compiled with version: 4.8.2 on 06 March 2015 16:10:06
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: /usr/local/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: 2.7.6 (default, Mar 22 2014, 23:03:41) [GCC 4.8.2]
Set PythonHome to /home/ubuntu/.virtualenvs/env1
ImportError: No module named site
VACUUM: unix socket /tmp/mysite.sock removed.
Where is
ImportError: No module named site on Ubuntu
coming from and how can I fix this?
Try no-site = True in mysite_uwsgi.ini file.