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.
This commit is contained in:
Alex Vandiver 2022-03-25 15:32:39 -07:00 committed by Tim Abbott
parent 2df4ace441
commit e9596637e7
1 changed files with 11 additions and 5 deletions

View File

@ -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)