45

Can't remember where, but I read uWSGI can reload itself like Django development server when a project script is modified. I can't find that in the docs, nor in the internets. How can I do this?

I use Ubuntu 12.04 on my working machines and Debian Squeeze on stage & production server, Django 1.4 and uWSGI 1.2.

culebrón
  • 565
  • 1
  • 4
  • 7

5 Answers5

44

Reference: http://projects.unbit.it/uwsgi/wiki/Management

If you have started uwsgi with the --touch-reload=/path/to/special/file/usually/the.ini option, reloading your uWSGI is a simple matter of touch reloading that file with

touch /path/to/special/file/usually/the.ini

And if you want the "autoreload" capability, this is the tip that gets this done: http://projects.unbit.it/uwsgi/wiki/TipsAndTricks#uWSGIdjangoautoreloadmode

Calvin Cheng
  • 1,116
  • 3
  • 14
  • 17
39

There is a py-autoreload=N option in newer releases. Just set N to the frequency (in seconds) of checks (3 is a good value).

Eugene Yarmash
  • 2,383
  • 5
  • 32
  • 54
roberto
  • 1,812
  • 12
  • 8
  • 12
    "use only in development" according to [uwsgi docs](http://uwsgi-docs.readthedocs.org/en/latest/Options.html#py-auto-reload-py-autoreload-python-auto-reload-python-autoreload) – scytale Jan 28 '13 at 17:32
  • 4
    looks like [touch-reload=/some/file](http://uwsgi-docs.readthedocs.org/en/latest/Options.html#touch-reload) is a safer option – scytale Jan 28 '13 at 17:34
12

If you don't want lose the django autoreload, register this reload method (i.e: in settings.py):

import uwsgi
from uwsgidecorators import timer
from django.utils import autoreload

@timer(3)
def change_code_gracefull_reload(sig):
    if autoreload.code_changed():
        uwsgi.reload()

Now if you change your code it will be reloaded.

Author: Simone Federici

BorisHajduk
  • 259
  • 2
  • 7
1

As stated in docs to make uWSGI gracefully restart.

# using kill to send the signal
kill -HUP `cat /tmp/project-master.pid`
# or the convenience option --reload
uwsgi --reload /tmp/project-master.pid
# or if uwsgi was started with touch-reload=/tmp/somefile
touch /tmp/somefile
marcanuy
  • 248
  • 1
  • 3
  • 11
1

uwsgi also allow restart using kill SIGNAL. I use it as below:

# ps -efa | grep uwsgi | grep prod
app  13390 13383  0 07:40 ?        00:00:00 /usr/local/bin/uwsgi --ini /etc/uwsgi/apps-enabled/app_prod.ini
app  13417 13390  0 07:40 ?        00:00:00 /usr/local/bin/uwsgi --ini /etc/uwsgi/apps-enabled/app_prod.ini
app  13419 13390  0 07:40 ?        00:00:00 /usr/local/bin/uwsgi --ini /etc/uwsgi/apps-enabled/app_prod.ini
# kill -HUP 13390

If you run same command, you will see child procs pid will be changed as they are re-spawned by master. Also check uwsgi config for master/worker proc counts. This method is easy to integrate with ansible or other automation tools so goes easy to for remote use.

This doesn't need your original proc to be started with --touch-reload.

mrtipale
  • 111
  • 2