restart-server: Add a --only-django for rolling Django restarts.

This commit is contained in:
Alex Vandiver 2024-10-08 15:21:34 +00:00 committed by Tim Abbott
parent 4451db08c3
commit 44fde64c42
2 changed files with 38 additions and 33 deletions

View File

@ -691,11 +691,17 @@ def start_arg_parser(action: str, add_help: bool = False) -> argparse.ArgumentPa
parser.add_argument(
"--skip-checks", action="store_true", help="Skip syntax and database checks"
)
parser.add_argument(
which_services = parser.add_mutually_exclusive_group()
which_services.add_argument(
"--skip-client-reloads",
action="store_true",
help="Do not send reload events to web clients",
)
which_services.add_argument(
"--only-django",
action="store_true",
help=f"Only {action} Django (not Tornado or workers)",
)
if action == "restart":
parser.add_argument(
"--less-graceful",

View File

@ -122,23 +122,21 @@ aux_services = list_supervisor_processes(["go-camo", "smokescreen"], only_runnin
if aux_services:
subprocess.check_call(["supervisorctl", "start", *aux_services])
if args.only_django:
workers = []
check_services = ["zulip-django"]
else:
check_services = [*workers, "zulip-django", "zulip-tornado:*"]
# If none of the workers nor the application servers are running, this
# is actually a "start," not a restart, which means we will defer
# workers to later.
if (
action == "restart"
and len(
list_supervisor_processes([*workers, "zulip-django", "zulip-tornado:*"], only_running=True)
)
== 0
):
running_services = list_supervisor_processes(check_services, only_running=True)
if action == "restart" and len(running_services) == 0:
action = "start"
verbing = "Starting"
elif action == "start":
existing_services = list_supervisor_processes([*workers, "zulip-django", "zulip-tornado:*"])
running_services = list_supervisor_processes(
[*workers, "zulip-django", "zulip-tornado:*"], only_running=True
)
existing_services = list_supervisor_processes(check_services)
if existing_services == running_services:
logging.info("Zulip is already started; nothing to do!")
sys.exit(0)
@ -172,6 +170,7 @@ if action == "restart" and len(workers) > 0:
restart_or_start(worker)
if has_application_server():
if not args.only_django:
# Next, we restart the Tornado processes sequentially, in order to
# minimize downtime of the tornado service caused by too many
# Python processes restarting at the same time, resulting in each
@ -235,13 +234,13 @@ if has_application_server():
# If we were doing this non-gracefully, or starting as opposed to
# restarting, we need to turn the workers (back) on. There's no
# advantage to doing this not-all-at-once.
if action == "start" or args.less_graceful:
if (action == "start" or args.less_graceful) and not args.only_django:
workers = list_supervisor_processes(workers, only_running=False)
if workers:
logging.info("Starting workers")
subprocess.check_call(["supervisorctl", "start", *workers])
if has_application_server() and not args.skip_client_reloads:
if has_application_server() and not args.skip_client_reloads and not args.only_django:
# All of the servers have been (re)started; now enqueue events in
# the Tornado servers to tell clients to reload.
subprocess.check_call(["./scripts/reload-clients"])