20

I use a supervisor to run uWSGI application. Why uWSGI application does not always stop after stop supervisor? supervisor config:

[program:test]
autostart = true
user=root
command=uwsgi --master --workers  5 --disable-logging --socket 127.0.0.1:8888
--module web --callable app
priority=1
redirect_stderr=true
stdout_logfile = /data/log
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Bdfy
  • 23,141
  • 55
  • 131
  • 179

4 Answers4

41

By default supervisor send SIGTERM on stop. SIGTERM in uWSGI means 'brutal reload'.

You have to change it to QUIT or INT:

stopsignal=QUIT

should be enough

Another approach (discouraged) is adding --die-on-term to uWSGI command line to change its default behaviour

roberto
  • 12,723
  • 44
  • 30
  • why it's discouraged ? – Guillaume Vincent Jan 14 '14 at 13:32
  • 1
    Because you need this option only if you use supervisor. It is better to fix supervisor's behaviour in supervisor's config. – Raz Apr 04 '14 at 11:42
  • 2
    I have little experience with either method but when I was looking for the right config to use I found a few examples of problems that were apparently only solved by using `die-on-term` eg http://stackoverflow.com/a/22213404/202168 https://github.com/unbit/uwsgi/issues/296 – Anentropic Dec 05 '14 at 13:37
4
  1. project supervisor config file

    add stopsignal=INT

  2. project uwsgi config file

    remove daemonize=xxx.log to disable daemon mode

Color
  • 875
  • 9
  • 11
  • Great tip. With daemonize on in uwsgi, when controlled via sword i found the OS would run of memory and produce this error: [Errno 12] Cannot allocate memory – run_the_race Mar 15 '19 at 18:33
4

If you use "processes = #" into your uwsgi configuration, you also must use "master = true". If not, supervisor only will kill one of workers.

Then:

/etc/supervisor/conf.d/app.conf

stopsignal = QUIT

/etc/uwsgi/app.ini

processes = 4
master = true
nik_m
  • 11,825
  • 4
  • 43
  • 57
estevo
  • 941
  • 11
  • 11
  • I used `stopsignal = QUIT` but after stopped it in supervisorctl, some new uwsgi processes was created by pid 1. `stopsignal=INT` does the stop thing. – Kyan Nov 30 '17 at 06:59
1

If you are running your UWSGI with master and workers you need to add in your /etc/supervisor/conf.d/app.conf file

stopasgroup=false
killasgroup=false

or else no matter what stopping uwsgi will spawn more master and so is workers.

Kunal Mawar
  • 11
  • 1
  • 3