Skip to content

Commit

Permalink
Improve uWSGI and consul-template interactions on reloading (#2640)
Browse files Browse the repository at this point in the history
We fixed the `bind(): Address already in use [core/socket.c line 769]` error in LB
using `exit-on-reload = true` in uWSGI configuration. However, this prevents graceful
reloading.

I did some further investigation as noted in metabrainz/artwork-redirect#46
and have a better fix in mind now.

For the command field in `exec` block of consul template configuration, use
array format. This executes the command directly without spawning a shell wrapper
or setting a process group id. Both of which will interfere with forwarding
signals to the uWSGI process.
  • Loading branch information
amCap1712 authored Nov 27, 2023
1 parent 5e0a533 commit 502189b
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docker/services/api_compat/consul-template-api-compat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command uwsgi --die-on-term /etc/uwsgi/uwsgi-api-compat.ini"
command = ["run-lb-command", "uwsgi", "/etc/uwsgi/uwsgi-api-compat.ini"]
splay = "5s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
3 changes: 1 addition & 2 deletions docker/services/api_compat/uwsgi-api-compat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ log-x-forwarded-for=true
disable-logging = true
; quit uwsgi if the python app fails to load
need-app = true
; when uwsgi gets a sighup, quit completely and let runit restart us
exit-on-reload = true
die-on-term = true
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command python3 -u -m listenbrainz.metadata_cache.apple.runner"
command = ["run-lb-command", "python3", "-u", "-m", "listenbrainz.metadata_cache.apple.runner"]
splay = "60s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
2 changes: 1 addition & 1 deletion docker/services/labs_api/consul-template-labs-api.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command uwsgi --die-on-term /etc/uwsgi/uwsgi-labs-api.ini"
command = ["run-lb-command", "uwsgi", "/etc/uwsgi/uwsgi-labs-api.ini"]
splay = "5s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
3 changes: 1 addition & 2 deletions docker/services/labs_api/uwsgi-labs-api.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ log-x-forwarded-for=true
disable-logging = true
; quit uwsgi if the python app fails to load
need-app = true
; when uwsgi gets a sighup, quit completely and let runit restart us
exit-on-reload = true
; increase buffer size for requests that send a lot of mbids in query params
buffer-size = 8192
die-on-term = true
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command python3 -u -m listenbrainz.mbid_mapping_writer.mbid_mapping_writer"
command = ["run-lb-command", "python3", "-u", "-m", "listenbrainz.mbid_mapping_writer.mbid_mapping_writer"]
splay = "60s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command python3 -m listenbrainz.spark.spark_reader"
command = ["run-lb-command", "python3", "-m", "listenbrainz.spark.spark_reader"]
splay = "5s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command python3 -u -m listenbrainz.metadata_cache.spotify.runner"
command = ["run-lb-command", "python3", "-u", "-m", "listenbrainz.metadata_cache.spotify.runner"]
splay = "60s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command python3 -m listenbrainz.spotify_updater.spotify_read_listens"
command = ["run-lb-command", "python3", "-m", "listenbrainz.spotify_updater.spotify_read_listens"]
splay = "5s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command python3 -u -m listenbrainz.timescale_writer.timescale_writer"
command = ["run-lb-command", "python3", "-u", "-m", "listenbrainz.timescale_writer.timescale_writer"]
splay = "5s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
2 changes: 1 addition & 1 deletion docker/services/uwsgi/consul-template-uwsgi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command uwsgi --die-on-term /etc/uwsgi/uwsgi.ini"
command = ["run-lb-command", "uwsgi", "/etc/uwsgi/uwsgi.ini"]
splay = "5s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down
3 changes: 1 addition & 2 deletions docker/services/uwsgi/uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ log-x-forwarded-for=true
disable-logging = true
; quit uwsgi if the python app fails to load
need-app = true
; when uwsgi gets a sighup, quit completely and let runit restart us
exit-on-reload = true
; increase buffer size for requests that send a lot of mbids in query params
buffer-size = 8192
die-on-term = true
2 changes: 1 addition & 1 deletion docker/services/websockets/consul-template-websockets.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ template {
}

exec {
command = "run-lb-command python3 manage.py run_websockets -h 0.0.0.0 -p 3031"
command = ["run-lb-command", "python3", "manage.py", "run_websockets", "-h", "0.0.0.0", "-p", "3031"]
splay = "5s"
reload_signal = "SIGHUP"
kill_signal = "SIGTERM"
Expand Down

0 comments on commit 502189b

Please sign in to comment.