I have a Flask application running inside a container, where I have setup the logging with the StreamHandler(), so the logs are sent to stdout.
When my uwsgi.ini file includes a statement to redirect the logs to a file (by using logto), then the logs from the application are available in the log file intermixed with the uWSGI logs (as it is expected).
But when I remove the logto from the uwsgi.ini - because I want those logs sent to the Docker container stdout only the uWSGI logs are visible in the docker container logs, the application logs are not. (the uWSGI logs were there even before)
uwsgi.ini:
[uwsgi]
base = /app_home/app
wsgi-file = /app_home/app/wsgi.py
callable = app
socket = /tmp/uwsgi.sock
chmod-socket = 666
# Log directory - we needed this to be turned off, so the logs are sent to STDOUT
# logto = /var/log/uwsgi/app.log
vacuum = true
master = true
processes = 3
enable-threads = true
uid = app
gid = app
master-fifo = /tmp/fifo0
master-fifo = /tmp/fifo1
chdir = /app_home/app
When the logto is enabled, then the log file includes the app's logs (as it should):
[2019-03-05 17:19:05,415] INFO in __init__: Initial starting of app...
2019-03-05 17:19:05,415 (9) - INFO - Initial starting of app...- [in ./app/__init__.py:128, function:create_app]
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1ad49b0 pid: 9 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 9)
spawned uWSGI worker 1 (pid: 32, cores: 1)
Once the logto is disabled, then no log file (as expected), but no app logs in the Docker container log either. The docker container looks exactly the same as before:
2019-03-05T22:19:09.956784133Z 2019-03-05 17:19:09,956 CRIT Supervisor running as root (no user in config file)
2019-03-05T22:19:09.959701644Z 2019-03-05 17:19:09,959 INFO supervisord started with pid 1
2019-03-05T22:19:10.961366502Z 2019-03-05 17:19:10,961 INFO spawned: 'nginx' with pid 9
2019-03-05T22:19:10.963312945Z 2019-03-05 17:19:10,962 INFO spawned: 'uwsgi' with pid 10
2019-03-05T22:19:12.928470278Z 2019-03-05 17:19:12,928 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2019-03-05T22:19:12.928498809Z 2019-03-05 17:19:12,928 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
uWSGI documentation shows that the logs are sent to stdout/stderr by default (see https://uwsgi-docs.readthedocs.io/en/latest/Logging.html), so I don't really see a reason why the app's logs would be not sent to stdout with the uWSGI's own logs, but sent to a file with logto.
There are two issues:
As uWSGI is running in the Docker container with Supervisor, you need to make supervisor redirect the stdout of uwsgi to its stdout.
supervisord.conf:
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /app_home/app/uwsgi.ini --uid app --gid app --log-master
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
While this has worked with other applications (like nginx), it was not enough for uWSGI, see step #2:
A special flag (--log-master) needs to be added to uWSGI to delegate the logging to the master process:
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /app_home/app/uwsgi.ini --uid app --gid app --log-master
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
And then, the logs from the Flask applications are visible in the Docker container log.
This answer was posted as an edit to the question UWSGI does not redirect application stdout to stdout, only to file by the OP Zoltan Fedor under CC BY-SA 4.0.
I am doing multi-application nginx+uwsgi setup in django. I am following this documentation
to set up emperor mode for my project.
It works fine when I run "uwsgi --ini myproject_uwsgi.ini" but I am not able to deploy emperor mode following this documentation.
I have researched many docs but not able to find relevant information related to emperor mode setup.
My nginx.conf file:(angularJS frontend)
server {
listen 80;
server_name 192.168.xx.xx;
root /home/user/Myspace/workspace/Myproject_frontend/dist;
}
My "etc/uwsgi/vassals/uwsgi.ini" file looks like:
[uwsgi]
#Django-related settings
#Django's wsgi file
wsgi-file = /home/user/Myspace/workspace/myproject/myproject/wsgi.py
http = 192.168.xx.xx:8080
virtualenv = /home/user/Myspace/VENV_MYPROD
Also, i have created a uwsgi.service file in "/etc/systemd/system/uwsgi.service" to start emperor mode service and it looks like:
[Unit]
Description=uWSGI Emperor service
After=syslog.target
[Service]
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals/
RuntimeDirectory= uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
Please provide help on setting up uwsgi emperor mode.
I have gunicorn serving a django application. Nginx is used as a reverse proxy. And supervisord is used to manage gunicorn.
This is the supervisord config:
command = /opt/backend/envs/backend/bin/gunicorn msd.wsgi:application --name backend --bind 13.134.82.143:8030 --workers 5 --timeout 300 --user backend --group backend --log-level info --log-file /opt/backend/logs/gunicorn.log
directory = /opt/backend/backend
user = backend
group = backend
stdout_logfile = /opt/backend/logs/supervisor.log
redirect_stderr = true
Sometimes gunicorn workers time out. After that, I expect gunicorn to automatically reload the dead ones.
However, the strange thing is under heavy load, some workers cannot get back up saying:
Can't connect to ('13.134.82.143', 8030)
I think that the workers that timed out are left as a zombie and occupying the ports.
What can I do in such cases?
I've been trying to run my applications with emperor mode and got it working but the problem is the moment i run emperor mode my computer slows down like crazy and i can't do anything. My configuration files code for both applications are similar.
[uwsgi]
module = Restful
chdir = path
processes = 2
http-socket = :5001
chmod-socket = 660
vacuum = true
die-on-term = true
[uwsgi]
module = Flaskapp
chdir = /home/muba/PycharmProjects/Work/
wsgi-file = Work/wsgi.py
processes = 2
http-socket = :5000
chmod-socket = 660
vacuum = true
die-on-term = true
My code i run is
uwsgi --emperor vassals --uid http --gid http --master
It works and i see that both my apps are running at the same time but a few seconds later my laptop slows down. Anything I'm doing wrong? it was working the first time i tried then after that it slowed down. I also made an emperor.ini file in my vassals.
Wait you have an emperor.ini file? If it has configuration similar to what you have put in your uwsgi code, then it's probably running it twice and slowing down your computer?
I've some problem with run uwsgi.
I run application(Pyramid with zerorpc, gevent) in uwsgi. And some requests fails.
Python writes this error:
Assertion failed: ok (bundled/zeromq/src/mailbox.cpp:79)
Aborted
uWSGI worker 1 screams: UAAAAAAH my master disconnected: i will kill myself !!!
Why there might be such a problem?
uwsgi config:
[uwsgi]
socket = /tmp/sock.sock
chmod-socket = 666
master = true
processes = 1
vacuum = true
i run so:
uwsgi --ini-paste development.ini
the whole zeromq magic is managed by a background thread. A property of threads is that they "disappear" after fork(), so zeromq will not work in your uWSGI worker. Just add
lazy-apps = true
in your uWSGI options to load zeromq (read: your app) after each fork()