Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

puppet: Use lazy-apps and uwsgi control sockets for rolling reloads.

Alex Vandiver6218ed91c2b7
diff --git a/docs/production/deployment.md b/docs/production/deployment.md
index e7f5cf678f7..4b8a782a4d4 100644
--- a/docs/production/deployment.md
+++ b/docs/production/deployment.md
@@ -623,6 +623,14 @@ override is useful both Docker systems (where the above algorithm
might see the host's memory, not the container's) and/or when using
remote servers for postgres, memcached, redis, and RabbitMQ.
+#### `rolling_restart`
+
+If set to a non-empty value, when using `./scripts/restart-server` to
+restart Zulip, restart the uwsgi processes one-at-a-time, instead of
+all at once. This decreases the number of 502's served to clients, at
+the cost of slightly increased memory usage, and the possibility that
+different requests will be served by different versions of the code.
+
#### `uwsgi_buffer_size`
Override the default uwsgi buffer size of 8192.
diff --git a/puppet/zulip/manifests/app_frontend_base.pp b/puppet/zulip/manifests/app_frontend_base.pp
index 011763aae0c..fade71baf5e 100644
--- a/puppet/zulip/manifests/app_frontend_base.pp
+++ b/puppet/zulip/manifests/app_frontend_base.pp
@@ -119,6 +119,12 @@ class zulip::app_frontend_base {
notify => Service[$zulip::common::supervisor_service],
}
+ $uwsgi_rolling_restart = zulipconf('application_server', 'rolling_restart', '')
+ if $uwsgi_rolling_restart == '' {
+ file { '/home/zulip/deployments/uwsgi-control':
+ ensure => absent,
+ }
+ }
$uwsgi_listen_backlog_limit = zulipconf('application_server', 'uwsgi_listen_backlog_limit', 128)
$uwsgi_buffer_size = zulipconf('application_server', 'uwsgi_buffer_size', 8192)
$uwsgi_processes = zulipconf('application_server', 'uwsgi_processes', $uwsgi_default_processes)
diff --git a/puppet/zulip/templates/uwsgi.ini.template.erb b/puppet/zulip/templates/uwsgi.ini.template.erb
index 6d72b2b9c48..c43d66ec350 100644
--- a/puppet/zulip/templates/uwsgi.ini.template.erb
+++ b/puppet/zulip/templates/uwsgi.ini.template.erb
@@ -16,6 +16,13 @@ gid=zulip
stats=/home/zulip/deployments/uwsgi-stats
+<% if @uwsgi_rolling_restart != '' -%>
+master-fifo=/home/zulip/deployments/uwsgi-control
+# lazy-apps are required for rolling restarts:
+# https://uwsgi-docs.readthedocs.io/en/latest/articles/TheArtOfGracefulReloading.html#preforking-vs-lazy-apps-vs-lazy
+lazy-apps=true
+<% end -%>
+
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true
diff --git a/scripts/restart-server b/scripts/restart-server
index a8bb94780a6..6923988a667 100755
--- a/scripts/restart-server
+++ b/scripts/restart-server
@@ -13,6 +13,7 @@ from scripts.lib.zulip_tools import (
ENDC,
OKGREEN,
WARNING,
+ get_config,
get_config_file,
get_tornado_ports,
has_application_server,
@@ -128,8 +129,29 @@ if has_application_server():
subprocess.check_call(["supervisorctl", action, "zulip-tornado:*"])
# Finally, restart the Django uWSGI processes.
- logging.info("%s django server", verbing)
- subprocess.check_call(["supervisorctl", action, "zulip-django"])
+ if (
+ action == "restart"
+ and not args.less_graceful
+ and get_config(config_file, "application_server", "rolling_restart") != ""
+ and os.path.exists("/home/zulip/deployments/uwsgi-control")
+ ):
+ # See if it's currently running
+ uwsgi_status = subprocess.run(
+ ["supervisorctl", "status", "zulip-django"],
+ stdout=subprocess.DEVNULL,
+ )
+ if uwsgi_status.returncode == 0:
+ logging.info("Starting rolling restart of django server")
+ with open("/home/zulip/deployments/uwsgi-control", "w") as control_socket:
+ # "c" is chain-reloading:
+ # https://uwsgi-docs.readthedocs.io/en/latest/MasterFIFO.html#available-commands
+ control_socket.write("c")
+ else:
+ logging.info("Starting django server")
+ subprocess.check_call(["supervisorctl", "start", "zulip-django"])
+ else:
+ logging.info("%s django server", verbing)
+ subprocess.check_call(["supervisorctl", action, "zulip-django"])
using_sso = subprocess.check_output(["./scripts/get-django-setting", "USING_APACHE_SSO"])
if using_sso.strip() == b"True":