mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
7c4293a7d3switched to checking if the service was already running, and use `supervisorctl start` if it was not. Unfortunately, `list_supervisor_processes("zulip-tornado:*")` did not include `zulip-tornado`, and as such a non-sharded process was always considered to _not_ be running, and was thus started, not restarted. Starting an already-started service is a no-op, and thus non-sharded tornado processes were never restarted. The observed behaviour is that requests to the tornado process attempt to load the user from the cache, with a different prefix from Django, and immediately invalidate the session and eject the user back to the login page. Fix the `list_supervisor_processes` logic to match without the trailing `:*`. (cherry picked from commit65e19c4fbd)
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
import socket
|
|
from http.client import HTTPConnection
|
|
from typing import Dict, List, Optional, Tuple, Union
|
|
from xmlrpc import client
|
|
|
|
|
|
class UnixStreamHTTPConnection(HTTPConnection):
|
|
def connect(self) -> None:
|
|
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
self.sock.connect(self.host)
|
|
|
|
|
|
class UnixStreamTransport(client.Transport):
|
|
def __init__(self, socket_path: str) -> None:
|
|
self.socket_path = socket_path
|
|
super().__init__()
|
|
|
|
def make_connection(
|
|
self, host: Union[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: Optional[List[str]] = None, *, only_running: Optional[bool] = 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[:-1]) or name == filter_name[:-2]
|
|
):
|
|
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"] == "RUNNING"):
|
|
results.append(name)
|
|
return results
|