Files
zulip/scripts/refresh-sharding-and-restart
Alex Vandiver 01664a1a10 sharding: Swap new config into place during restart-server.
This allows restart-server, before moving the new config into place,
to perform a diff and only restart the affected Tornado ports.
2025-10-07 13:19:05 -07:00

30 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
# Stand up the new zulip-tornado supervisor instances, and write out
# the newly generated config files, with .tmp suffix
SUPPRESS_SHARDING_NOTICE=1 "$(dirname "$0")/zulip-puppet-apply" -f
# Verify, before we move them into place
if ! [ -e /etc/zulip/nginx_sharding_map.conf.tmp ] || ! [ -e /etc/zulip/sharding.json.tmp ]; then
echo "No sharding updates found to apply."
exit 1
fi
# In the ordering of operations below, the crucial detail is that
# Django, Tornado, and workers need to be restarted before reloading
# nginx. Django and Tornado have in-memory maps of which realm belongs
# to which shard. Reloading nginx will cause users' tornado requests
# to be routed according to the new sharding scheme. If that happens
# before Django is restarted, updating its realm->shard map, users on
# realms whose shard has changed will have their tornado requests
# handled by the new tornado process, while Django will still use the
# old process for its internal communication with tornado when
# servicing the user's requests. That's a bad state that leads to
# clients getting into reload loops ending in crashing on 500 response
# while Django is restarting. For this reason it's important to
# reload nginx only after Django and Tornado.
"$(dirname "$0")/restart-server" --skip-client-reloads --tornado-reshard
service nginx reload