Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
import socket
|
|
import time
|
|
from http.client import HTTPConnection
|
|
from xmlrpc import client
|
|
|
|
from typing_extensions import override
|
|
|
|
|
|
class UnixStreamHTTPConnection(HTTPConnection):
|
|
@override
|
|
def connect(self) -> None:
|
|
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
connected = False
|
|
for i in range(2):
|
|
try:
|
|
self.sock.connect(self.host)
|
|
connected = True
|
|
break
|
|
except FileNotFoundError:
|
|
# Backoff and retry
|
|
time.sleep(2**i)
|
|
if not connected:
|
|
raise Exception(
|
|
"Failed to connect to supervisor -- check that it is running, by running 'service supervisor status'"
|
|
)
|
|
|
|
|
|
class UnixStreamTransport(client.Transport):
|
|
def __init__(self, socket_path: str) -> None:
|
|
self.socket_path = socket_path
|
|
super().__init__()
|
|
|
|
@override
|
|
def make_connection(self, host: tuple[str, dict[str, str]] | str) -> UnixStreamHTTPConnection:
|
|
return UnixStreamHTTPConnection(self.socket_path)
|
|
|
|
|
|
def rpc() -> client.ServerProxy:
|
|
return client.ServerProxy(
|
|
"http://localhost", transport=UnixStreamTransport("/var/run/supervisor.sock")
|
|
)
|
|
|
|
|
|
def list_supervisor_processes(
|
|
filter_names: list[str] | None = None, *, only_running: bool | None = None
|
|
) -> 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:
|
|
# zulip-tornado:* matches zulip-tornado:9800 and zulip-tornado
|
|
if filter_name.endswith(":*") and (
|
|
name.startswith(filter_name.removesuffix("*"))
|
|
or name == filter_name.removesuffix(":*")
|
|
):
|
|
match = True
|
|
break
|
|
if name == filter_name:
|
|
match = True
|
|
break
|
|
if not match:
|
|
continue
|
|
|
|
if only_running is None:
|
|
results.append(name)
|
|
elif only_running == (process["statename"] in ("RUNNING", "STARTING")):
|
|
results.append(name)
|
|
|
|
return results
|