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("[ ]"): if line_str.startswith("[ ]"):
migrations_needed = True migrations_needed = True
if (not args.skip_puppet or migrations_needed) and IS_SERVER_UP: # NOTE: Here begins the most likely critical period, where we may be
# By default, we shut down the service to apply migrations and # shutting down the server; we should strive to minimize the number of
# Puppet changes, to minimize risk of issues due to inconsistent # steps that happen between here and the "Restarting Zulip" line
# state. # below.
shutdown_server()
if rabbitmq_dist_listen: if rabbitmq_dist_listen:
shutdown_server() 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 # characters long by a good randomizer, it would be 96 bits and
# more than sufficient. We generate, using good randomness, a # more than sufficient. We generate, using good randomness, a
# 255-character cookie, the max allowed length. # 255-character cookie, the max allowed length.
shutdown_server()
logging.info("Generating a secure erlang cookie...") logging.info("Generating a secure erlang cookie...")
subprocess.check_call(["./scripts/setup/generate-rabbitmq-cookie"]) subprocess.check_call(["./scripts/setup/generate-rabbitmq-cookie"])
@ -357,11 +357,17 @@ if classes != new_classes:
if not args.skip_puppet: 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...") logging.info("Applying Puppet changes...")
subprocess.check_call(["./scripts/zulip-puppet-apply", "--force"]) subprocess.check_call(["./scripts/zulip-puppet-apply", "--force"])
subprocess.check_call(["apt-get", "-y", "--allow-downgrades", "upgrade"]) subprocess.check_call(["apt-get", "-y", "--allow-downgrades", "upgrade"])
if migrations_needed: if migrations_needed:
# Database migrations assume that they run on a database in
# quiesced state.
shutdown_server()
logging.info("Applying database migrations...") logging.info("Applying database migrations...")
subprocess.check_call(["./manage.py", "migrate", "--noinput"], preexec_fn=su_to_zulip) subprocess.check_call(["./manage.py", "migrate", "--noinput"], preexec_fn=su_to_zulip)