1

I occasionally have issues where a db will restart or something similar. In these cases I need to go in and manually restart uwsgi.

Is it possible to setup uwsgi to restart on 500 errors? Ideally I could get the worker to restart on a number of of 500 errors, not on each one.

emperorcezar
  • 113
  • 5

1 Answers1

4

you can use the metric subsystem, adding a metric counting the 500 errors.

Metrics can have a threshold triggering an alarm (the reload in your case)

[uwsgi]

http-socket = :9092

; reload the instance when touching
touch-reload = /tmp/restart

; create a new alarm restarting the instance
alarm = database_reloaded cmd:touch /tmp/restart

; create a metric for couting 500s
metric = 500counter
; create a metric threshold, resetting the metric to 0 when hitting 5
; the metric alarm triggers the restart of the instance too
metric-alarm = key=500counter,value=5,alarm=database_reloaded,rate=60,reset=0

; increment metric whenever a 500 is generated
final-route-status = 500 metricinc:500counter
roberto
  • 1,827
  • 12
  • 8
  • This still works in uwsgi 2.0.20! Hint: if it does not work, check if your uwsgi has pcre support (it will complain loudly in the log during startup if it does not). – thule May 27 '22 at 16:46