From 88c3f560ae97d6639a3789ea3f3dec9b27af6e6b Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 20 Jan 2022 01:17:41 +0000 Subject: [PATCH] supervisor: Add a filter for only(-not)-running. --- scripts/lib/supervisor.py | 9 +++++++-- scripts/restart-server | 8 +++++--- scripts/stop-server | 6 ++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/lib/supervisor.py b/scripts/lib/supervisor.py index 0e37f5d0cf..6e1984ab34 100644 --- a/scripts/lib/supervisor.py +++ b/scripts/lib/supervisor.py @@ -27,7 +27,9 @@ def rpc() -> client.ServerProxy: ) -def list_supervisor_processes(*filter_names: str) -> List[str]: +def list_supervisor_processes( + filter_names: Optional[List[str]] = None, *, only_running: Optional[bool] = None +) -> List[str]: results = [] processes = rpc().supervisor.getAllProcessInfo() assert isinstance(processes, list) @@ -49,5 +51,8 @@ def list_supervisor_processes(*filter_names: str) -> List[str]: if not match: continue - results.append(name) + if only_running is None: + results.append(name) + elif only_running == (process["statename"] == "RUNNING"): + results.append(name) return results diff --git a/scripts/restart-server b/scripts/restart-server index 06bbad7165..4093d2e463 100755 --- a/scripts/restart-server +++ b/scripts/restart-server @@ -71,7 +71,7 @@ if has_application_server(): if action == "start" or args.less_graceful: workers.append("zulip-workers:*") else: - workers.extend(list_supervisor_processes("zulip-workers:*")) + workers.extend(list_supervisor_processes(["zulip-workers:*"])) if has_application_server(once=True): # These used to be included in "zulip-workers:*"; since we may @@ -81,8 +81,10 @@ if has_application_server(): # `supervisorctl`. workers.extend( list_supervisor_processes( - "zulip_deliver_scheduled_emails", - "zulip_deliver_scheduled_messages", + [ + "zulip_deliver_scheduled_emails", + "zulip_deliver_scheduled_messages", + ] ) ) diff --git a/scripts/stop-server b/scripts/stop-server index a1a6ea0af9..912cf4c761 100755 --- a/scripts/stop-server +++ b/scripts/stop-server @@ -48,8 +48,10 @@ if has_application_server(): # if they currently exist according to `supervisorctl`. services.extend( list_supervisor_processes( - "zulip_deliver_scheduled_emails", - "zulip_deliver_scheduled_messages", + [ + "zulip_deliver_scheduled_emails", + "zulip_deliver_scheduled_messages", + ] ), )