2

OK I have Django, nginx and uWSGI set up on my server...the problem is I start uWSGI manually via this command:

uwsgi -s /home/user/sites/sock/uwsgi.sock -t 10 -M -p 1 -C --pythonpath /home/user/sites/ -w mysite.django_wsgi

And it's working great. The thing I would like to do is use supervisord to control the uWSGI processes (start, stop, etc.). How would I do this, what would the supervisord config look like?

Kenny Rasschaert
  • 9,045
  • 3
  • 42
  • 58
Veles
  • 135
  • 1
  • 7

2 Answers2

5

I found this was pretty confusing until I discovered emperor mode.

This means you can do one supervisord instance to manage all of your configs:

[program:uwsgi]
command=/usr/local/bin/uwsgi --emperor /etc/uwsgi/apps-enabled
stopsignal=QUIT
autostart=true
autorestart=true
redirect_stderr=true

And then you'd pop any config files (ini, xml, yaml) for apps into the /etc/uwsgi/apps-enabled directory.

Not sure if this works with 0.9, but defintely works with 1.0.

Here's an example ini for a Flask app:

[uwsgi]
socket = /tmp/uwsgi_%n.sock
module = wire:app
chdir = /srv/%n/wire
env = WIRE_SETTINGS=/srv/%n/wire/config.py
virtualenv = /srv/%n
uid = wire
gid = www-data
single-interpreter = false
chmod = 770
processes = 3
0

Here is a working supervisor conf file (normal mode, not emperor mode) :

[program:frite]
command=/home/mep/envs/frite_prod/bin/uwsgi
  --home frite_prod
  --module frite_deploy_wsgi
  --socket /home/frite/envs/frite_prod/frite.sock
  --chmod-socket 666
  --pythonpath /home/mep/envs/frite_prod/fr-frite
  --pythonpath /home/mep/envs/frite_prod/fr-frite/frite
  --processes 8
  --master -L -l 250 -z 5
  --post-buffering 1
directory=/home/frite/envs/
environment=DJANGO_SETTINGS_MODULE='frite.settings'
user=frite
autostart=true
autorestart=true
stdout_logfile=/home/frite/envs/frite_prod/uwsgi.log
redirect_stderr=true
stopsignal=QUIT

Your app need to be installed in a virtualenv. (And in this example I have the app running as "frite" user. So I have created a unix user with sudo addusr or something and put the virtualenvs and files there. So that it's isolated from the rest of the system.

And frite_deploy_wsgi.py is a kind of launcher that contains only :

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Cheers

dwarfy
  • 121
  • 1
  • 6