T
T
Teslaman2018-07-23 21:54:37
Python
Teslaman, 2018-07-23 21:54:37

How to deploy multiple projects on uWSGI?

Hello. I've been struggling with the problem for the third day, I need help.
Problem:
There are two projects, one on django, the other on flask, you need to deploy them on VPS (Nginx + uWSGI). I set up Nginx without problems, but I can’t figure it out with uWSGI.
Settings:
Each project has its own virtual environment with installed dependencies (python 3.6.6). The system itself has python2.7 and python3.5 installed (version 3.6 compiled from source and put in /opt, from which virtualenvs were made).
uWSGI is installed system wide.
configs:

uWSGI Emperor
[uwsgi]
emperor = /home/teslik/webapps/.uwsgi
uid = www-data
gid = www-data
master = true
enable-threads = true

uWSGI blog
[uwsgi]
socket = /tmp/blog.sock
chmod-socket = 666
chown-socket = www-data:www-data
logfile-chown = true
processes = 1
threads = 2
virtualenv = /home/teslik/webapps/.virtualenvs/blog
chdir = /home/teslik/webapps/apps/blog
wsgi-file = TeslikBlog/wsgi.py
vacuum = true
plugin = python3
logto = /home/teslik/webapps/.logs/blog/uwsgi.log

uWSGI cryptobot
[uwsgi]
socket = /tmp/cryptobot.sock
chmod-socket = 666
chown-socket = www-data:www-data
logfile-chown = true
processes = 1
threads = 2
virtualenv = /home/teslik/webapps/.virtualenvs/cryptobot
chdir = /home/teslik/webapps/apps/cryptobot/app
module = bot:app
vacuum = true
plugin = python3
logto = /home/teslik/webapps/.logs/cryptobot/uwsgi.log


I get the following result:
systemd

uwsgi.service - uWSGI Emperor
Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2018-07-23 19:27:44 UTC; 7min ago
Main PID: 18381 (uwsgi)
Status: "The Emperor is governing 2 vassals"
Tasks: 8
Memory: 16.6M
CPU: 144ms
CGroup: /system.slice/uwsgi.service
├─18381 /usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
├─18384 /usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
├─18390 /usr/bin/uwsgi-core --ini blog.ini
├─18391 /usr/bin/uwsgi-core --ini cryptobot.ini
├─18392 /usr/bin/uwsgi-core --ini blog.ini
└─18393 /usr/bin/uwsgi-core --ini cryptobot.ini
Jul 23 19:27:44 awshost systemd[1]: Started uWSGI Emperor.
Jul 23 19:27:44 awshost uwsgi[18381]: *** starting uWSGI Emperor ***
Jul 23 19:27:44 awshost uwsgi[18381]: *** has_emperor mode detected (fd: 7) ***
Jul 23 19:27:44 awshost uwsgi[18381]: [uWSGI] getting INI configuration from blog.ini
Jul 23 19:27:44 awshost uwsgi[18381]: *** has_emperor mode detected (fd: 8) ***
Jul 23 19:27:44 awshost uwsgi[18381]: [uWSGI] getting INI configuration from cryptobot.ini
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal blog.ini has been spawned
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal cryptobot.ini has been spawned
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal blog.ini is ready to accept requests
Jul 23 19:27:44 awshost uwsgi[18381]: Mon Jul 23 19:27:44 2018 - [emperor] vassal cryptobot.ini is ready to accept requests
tail -f blof/uwsgi.log

*** Starting uWSGI 2.0.12-debian (64bit) on [Mon Jul 23 19:27:44 2018] ***
compiled with version: 5.4.0 20160609 on 31 August 2017 21:02:04
os: Linux-4.4.0-1062-aws #71-Ubuntu SMP Fri Jun 15 10:07:39 UTC 2018
nodename: awshost
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/teslik/webapps/.uwsgi
detected binary path: /usr/bin/uwsgi-core
chdir() to /home/teslik/webapps/apps/blog
your processes number limit is 3900
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/blog.sock fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
PEP 405 virtualenv detected: /home/teslik/webapps/.virtualenvs/blog
Set PythonHome to /home/teslik/webapps/.virtualenvs/blog
Python main interpreter initialized at 0x8730c0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 166144 bytes (162 KB) for 2 cores
*** Operational MODE: threaded ***
Traceback (most recent call last):
File "TeslikBlog/wsgi.py", line 12, in
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django'
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: 18390)
spawned uWSGI worker 1 (pid: 18392, cores: 2)
tail -f cryptobot/uwsgi.log

*** Starting uWSGI 2.0.12-debian (64bit) on [Mon Jul 23 19:27:44 2018] ***
compiled with version: 5.4.0 20160609 on 31 August 2017 21:02:04
os: Linux-4.4.0-1062-aws #71-Ubuntu SMP Fri Jun 15 10:07:39 UTC 2018
nodename: awshost
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/teslik/webapps/.uwsgi
detected binary path: /usr/bin/uwsgi-core
chdir() to /home/teslik/webapps/apps/cryptobot/app
your processes number limit is 3900
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/cryptobot.sock fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
PEP 405 virtualenv detected: /home/teslik/webapps/.virtualenvs/cryptobot
Set PythonHome to /home/teslik/webapps/.virtualenvs/cryptobot
Python main interpreter initialized at 0x219f0e0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 166144 bytes (162 KB) for 2 cores
*** Operational MODE: threaded ***
Traceback (most recent call last):
File "./bot.py", line 1, in
import flask
ImportError: No module named 'flask'
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: 18391)
spawned uWSGI worker 1 (pid: 18393, cores: 2)
The same logs as a picture
5b562e61d6b77905951621.png

uWSGI doesn't import dependencies from virtual environments for some reason. The paths in the configs are correct.
I don’t know where to dig anymore, I reread the documentation, manuals for hours, and I still don’t understand why. Maybe there are uWSGI experts here. I will be very grateful for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2018-07-23
@Teslaman

> python3.7 -m venv env
> ./env/bin/pip3.7 install flask
> ./env/bin/pip3.7 install uwsgi
> ./env/bin/uwsgi --python-version 
3.7.0

> uwsgi --file app.py -s :80
['.', '', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']

> ./env/bin/uwsgi --file app.py -s :80
['.', '', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/tmp/env/lib/python3.7/site-packages']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question