uwsgi emperor share and use a common default ini within projects - flask

I'm using the uwsgi Emperor to manage multiple Flask apps, and for each individual app, I have several ini configs, e.g. local.ini, production.ini that I want to share common ini features from a central default.ini. And I'd like be able to do this for multiple projects, i.e. different projects can have different defaults. However, I cannot get the emperor to follow the symlinks to recognize the default.ini file. How do I get the emperor to follow symlinks so each project can understand its default.ini location? I always get the error
realpath() of default.ini failed: No such file or directory
emperor.ini setup file
[uwsgi]
emperor = /www/uwsgi/vassals
emperor-broodlord = 40
logto = /www/uwsgi/log/emperor.log
master = true
thunder-lock = true
enable-threads = true
stats = /tmp/empstats.sock
die-on-term = true
My vassals directory is set up with symlinks that point to the respective projects ini files
uwsgi_app1.ini -> /path/to/project1/local.ini
uwsgi_app2.ini -> /path/to/project2/local.ini
For each separate project, I have a default.ini which contains common settings I want to use for both local and production environments, for that project.
Project1
default.ini
[uwsgi]
file = %(wwwdir)/%(module)/run_%(app_name)
daemonize = %(wwwdir)/%(module)/log/%(app_name).log
socket = %(socketdir)/uwsgi_%(app_name).sock
stats = %(socketdir)/%(module)_stats.sock
master = true
processes = 4
chmod-socket = 666
vacuum = true
thunder-lock = true
enable-threads = true
lazy-apps = true
with local.ini and production.ini, having slightly different variables, being
local
[uwsgi]
callable = app
wwwdir = /localwww/
socketdir = /tmp
module = app1
app_name = app1
ini = default.ini
production
[uwsgi]
callable = app
wwwdir = /home/var-www/
socketdir = /run/uwsgi/tmp
module = app1
app_name = app1
ini = default.ini
If I use the %p magic variable to specify the absolute path, it instead points to the emperor vassal directory www/uwsgi/vassals/default.ini, rather than the real path.

I am using a full path to the default.ini in the project file...
ini = /path/to/my/project/config/uwsgi/defaults.ini

Related

Why my project uwsgi.ini is throwing Internal Server Error?

I am configuring a Django Nginx Server. Up to this stage: uwsgi --socket ProjetAgricole.sock --module ProjetAgricole.wsgi --chmod-socket=666 everything is working fine. However, after configuring the .ini file, and run the uwsgi --ini ProjetAgricole_uwsgi.ini file,I am getting this ouput [uWSGI] getting INI configuration from ProjetAgricole_uwsgi.ini. But when I open the app from the browser I am getting Internal Server Error
Here is my .ini file:
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/dnsae/my_project/ProjetAgricole/
# Django's wsgi file
module = ProjetAgricole.wsgi
# the virtualenv (full path)
home = /home/dnsae/my_project/my_venv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /home/dnsae/my_project/ProjetAgricole/ProjetAgricole.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
# daemonize uwsgi and write message into given log
daemonize = /home/dnsae/my_project/uwsgi-emperor.log
I restarted the server but still I am getting the same error.
Please assist me.

Logging in Django does not work when using uWSGI

I have a problem logging into a file using python built-in module.
Here is an example of how logs are generated:
logging.info('a log message')
Logging works fine when running the app directly through Python. However when running the app through uWSGI, logging does not work.
Here is my uWSGI configuration:
[uwsgi]
module = myapp.app:application
master = true
processes = 5
uid = nginx
socket = /run/uwsgi/myapp.sock
chown-socket = nginx:nginx
chmod-socket = 660
vacuum = true
die-on-term = true
logto = /var/log/myapp/myapp.log
logfile-chown = nginx:nginx
logfile-chmod = 640
EDIT:
The path /var/log/myapp/myapp.log is logging nginx access logs. There is another path configured in a settings.py file. The 2nd path is where application logs are ment to go. But there are non when using uWSGI.
Thanks in advance

(internal error) Ngnix + uwsgi +django : no module named django

So im trying to deploy a django app with nginx and uwsgi , ngnix is running well and the django app is working well with manage.py runserver , but when i try to deploy it with uwsgi it said Internal Server Error , and when i check my uwsgi logs that what i get (No module named django)
the virtualenv python version is 3.6.9 ,i'dont know if this error is caused because of imcompatibilty with python version of virtual environement and the Uwsgi one or just because i missed somethings , my uwsgi specs are
this is my uwsgi ini file :
[uwsgi]
vhost = true
plugins = python
socket = /tmp/mainsock
master = true
enable-threads = true
processes = 4
wsgi-file = /var/www/PTapp-launch/ptapp/wsgi.py
virtualenv = /var/www/venv/site
chdir = /var/www/PTapp-launch
touch-reload = /var/www/PTapp-launch/reload
env = DJANGO_ENV=production
env = DATABASE_NAME=personal_trainer
env = DATABASE_USER=postgres
env = DATABASE_PASSWORD=********
env = DATABASE_HOST=localhost
env = DATABASE_PORT=5432
env = ALLOWED_HOSTS=141.***.***.***
i have finally found the problem , when i was running manage.py runserver i had to use sudo , but when i didnt it was throwing the same error , (no module named Django) , so what i did its i uninstall all requirements and then use super user to create new virtual environnement and link it in uwsgi.ini, i also restart both of nginx and uwsgi, so everything work fine now ...

How does Django manage different subdomains on one Django project?

I want my Django project to be accessible at many different endpoints. For one app, I want it accessible at app.domain.com and for another app I want it accessible at dashboard.domain.com. How can I achieve this? I am using AWS Elastic Beanstalk and Route 53.
I tried looking at Django's djangoproject.com and their Github repo, as they do this. However, I couldn't figure it out. Thanks!
You can define two settings.py file, with two associated urls.py files :
app_settings.py
from my_project.settings import *
ROOT_URLCONF = 'my_project.app_urls'
ALLOWED_HOSTS = ['app.domain.com']
dashboard_settings.py
from my_project.settings import *
ROOT_URLCONF = 'my_project.dashboard_urls'
ALLOWED_HOSTS = ['dashboard.domain.com']
Define your urls for each website respectively in my_project/app_urls.py and my_project/dashboard_urls.py
Then start two instances of your django project (with uwsgi, gunicorn ou whatever you use) with those two distinct settings files (using DJANGO_SETTINGS_MODULE environment variable for example).
This way, both instances shares the same codebase but exposes distinct urls.
For example, using uwsgi, you could have those two files (with distinct ports) :
app.ini
[uwsgi]
http = 127.0.0.1:8001
module = my_project.wsgi
processes = 4
threads = 2
pidfile = app.pid
env = DJANGO_SETTINGS_MODULE=my_project.app_settings
dashboard.ini
[uwsgi]
http = 127.0.0.1:8002
module = my_project.wsgi
processes = 4
threads = 2
pidfile = app.pid
env = DJANGO_SETTINGS_MODULE=my_project.dashboard_settings

uwsgi and flask - cannot import name "appl"

I created several servers, without any issue, with the stack nginx - uwsgi - flask using virtualenv.
with the current one uwsgi is throwing the error cannot import name "appl"
here is the myapp directory structure:
/srv/www/myapp
+ run.py
+ venv/ # virtualenv
+ myapp/
+ init.py
+ other modules/
+ logs/
here is the /etc/uwsgi/apps-avaliable/myapp.ini
[uwsgi]
# Variables
base = /srv/www/myapp
app = run
# Generic Config
# plugins = http, python
# plugins = python
home = %(base)/venv
pythonpath = %(base)
socket = /tmp/%n.sock
module = %(app)
callable = appl
logto = %(base)/logs/uwsgi_%n.log
and this is run.py
#!/usr/bin/env python
from myapp import appl
if __name__ == '__main__':
DEBUG = True if appl.config['DEBUG'] else False
appl.run(debug=DEBUG)
appl is defined in myapp/ _ init _ .py as an instance of Flask()
(underscores spaced just to prevent SO to turn them into bold)
I accurately checked the python code and indeed if I activate manually the virtualenvironment and execute run.py manually everything works like a charm, but uwsgi keeps throwing the import error.
Any suggestion what should I search more ?
fixed it, it was just a read permissions issue. The whole python app was readable by my user but not by the group, therefore uwsgi could not find it.
This was a bit tricky because I deployed successfully many time with the same script and never had permissions issues