scripts: Re-implement list_supervisor_processes using API.

This commit is contained in:
Alex Vandiver 2022-01-20 00:01:13 +00:00 committed by Tim Abbott
parent 8e35cdb3da
commit 7243c3c73d
4 changed files with 28 additions and 21 deletions

View File

@ -25,3 +25,29 @@ def rpc() -> client.ServerProxy:
return client.ServerProxy(
"http://localhost", transport=UnixStreamTransport("/var/run/supervisor.sock")
)
def list_supervisor_processes(*filter_names: str) -> List[str]:
results = []
processes = rpc().supervisor.getAllProcessInfo()
assert isinstance(processes, list)
for process in processes:
if process["group"] != process["name"]:
name = f"{process['group']}:{process['name']}"
else:
name = process["name"]
if filter_names:
match = False
for filter_name in filter_names:
if filter_name.endswith(":*") and name.startswith(filter_name[:-1]):
match = True
break
if name == filter_name:
match = True
break
if not match:
continue
results.append(name)
return results

View File

@ -617,25 +617,6 @@ def has_application_server(once: bool = False) -> bool:
)
def list_supervisor_processes(*args: str) -> List[str]:
worker_status = subprocess.run(
["supervisorctl", "status", *args],
text=True,
stdout=subprocess.PIPE,
)
# `supervisorctl status` returns 3 if any are stopped, which is
# fine here; and exit code 4 is for no such process, which is
# handled below.
if worker_status.returncode not in (0, 3, 4):
worker_status.check_returncode()
processes = []
for status_line in worker_status.stdout.splitlines():
if not re.search(r"ERROR \(no such (process|group)\)", status_line):
processes.append(status_line.split()[0])
return processes
def has_process_fts_updates() -> bool:
return (
# Current path

View File

@ -8,6 +8,7 @@ import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from scripts.lib.supervisor import list_supervisor_processes
from scripts.lib.zulip_tools import (
DEPLOYMENTS_DIR,
ENDC,
@ -18,7 +19,6 @@ from scripts.lib.zulip_tools import (
get_tornado_ports,
has_application_server,
has_process_fts_updates,
list_supervisor_processes,
overwrite_symlink,
start_arg_parser,
)

View File

@ -7,13 +7,13 @@ import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from scripts.lib.supervisor import list_supervisor_processes
from scripts.lib.zulip_tools import (
ENDC,
OKGREEN,
WARNING,
has_application_server,
has_process_fts_updates,
list_supervisor_processes,
)
deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))