Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
restart-server: Log django-worker restart progress.
Ben Prew48b32e0a4324
diff --git a/scripts/restart-server b/scripts/restart-serverindex 8abc4aad46e..c4b49ba7921 100755--- a/scripts/restart-server+++ b/scripts/restart-server@@ -5,9 +5,11 @@ import loggingimport osimport pwdimport shlex+import socketimport subprocessimport sysimport time+from typing import Anysys.path.append(os.path.join(os.path.dirname(__file__), ".."))from scripts.lib.setup_path import setup_path@@ -79,6 +81,27 @@ def update_tornado_sharding() -> list[int]:return list(affected_tornados)+def uwsgi_stats() -> dict[str, Any]:+ try:+ with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:+ sock.settimeout(2)+ sock.connect("/home/zulip/deployments/uwsgi-stats")+ data = b""+ while True:+ chunk = sock.recv(4096)+ if not chunk:+ break+ data += chunk+ return json.loads(data)+ except (OSError, ValueError) as e:+ logging.warning("Unable to read uWSGI stats: %s", e)+ return {}+++def uwsgi_respawn_counts(stats: dict[str, Any]) -> dict[int, int]:+ return {w["id"]: w["respawn_count"] for w in stats.get("workers", [])}++action = "restart"if not sys.argv[0].endswith("restart-server"):action = "start"@@ -281,12 +304,20 @@ if has_application_server():# "c" is chain-reloading:# https://uwsgi-docs.readthedocs.io/en/latest/MasterFIFO.html#available-commandscontrol_socket.write("c")++ initial_counts = uwsgi_respawn_counts(uwsgi_stats())n = 0while not os.path.exists("/var/lib/zulip/django-workers.ready"):time.sleep(1)n += 1- if n % 5 == 0:- logging.info("...")+ if n % 5 != 0:+ continue+ worker_cnts = uwsgi_respawn_counts(uwsgi_stats())+ reloaded = sum(+ 1 for id, cnt in worker_cnts.items() if cnt > initial_counts.get(id, 1)+ )+ logging.info("%d of %d workers reloaded.", reloaded, len(initial_counts))+logging.info("Chain reloading complete")else:logging.info("Starting django server")