From e9596637e731b536a15704ee60fa42218c5bda4b Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 25 Mar 2022 15:32:39 -0700 Subject: [PATCH] upgrade: Move the shutdown_server calls to where they are relevant. shutdown_server is a noop if the server is already stopped; placing these in each block makes the logic more apparent. --- scripts/lib/upgrade-zulip-stage-2 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index bebf2708ad..94eb7c2204 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -309,11 +309,10 @@ if not args.skip_migrations: if line_str.startswith("[ ]"): migrations_needed = True -if (not args.skip_puppet or migrations_needed) and IS_SERVER_UP: - # By default, we shut down the service to apply migrations and - # Puppet changes, to minimize risk of issues due to inconsistent - # state. - shutdown_server() +# NOTE: Here begins the most likely critical period, where we may be +# shutting down the server; we should strive to minimize the number of +# steps that happen between here and the "Restarting Zulip" line +# below. if rabbitmq_dist_listen: shutdown_server() @@ -327,6 +326,7 @@ if cookie_size is not None and cookie_size == 20: # characters long by a good randomizer, it would be 96 bits and # more than sufficient. We generate, using good randomness, a # 255-character cookie, the max allowed length. + shutdown_server() logging.info("Generating a secure erlang cookie...") subprocess.check_call(["./scripts/setup/generate-rabbitmq-cookie"]) @@ -357,11 +357,17 @@ if classes != new_classes: if not args.skip_puppet: + # Puppet may adjust random services; to minimize risk of issues + # due to inconsistent state, we shut down the server first. + shutdown_server() logging.info("Applying Puppet changes...") subprocess.check_call(["./scripts/zulip-puppet-apply", "--force"]) subprocess.check_call(["apt-get", "-y", "--allow-downgrades", "upgrade"]) if migrations_needed: + # Database migrations assume that they run on a database in + # quiesced state. + shutdown_server() logging.info("Applying database migrations...") subprocess.check_call(["./manage.py", "migrate", "--noinput"], preexec_fn=su_to_zulip)