MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / reapStaleDevDb

Function reapStaleDevDb

apps/cloud/scripts/dev-db.ts:32–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30// cleanly — otherwise the new instance can't bind to PORT and the app ends
31// up talking to a stale PGlite with the wrong schema.
32function reapStaleDevDb() {
33 const out = execSync(`lsof -ti tcp:${PORT} -sTCP:LISTEN 2>/dev/null || true`, {
34 encoding: "utf8",
35 });
36 const pids = out.trim().split("\n").filter(Boolean);
37 if (pids.length === 0) return false;
38
39 for (const pid of pids) {
40 const cmd = execSync(`ps -p ${pid} -o args= 2>/dev/null || true`, {
41 encoding: "utf8",
42 }).trim();
43 if (!cmd.includes("dev-db.ts")) {
44 console.error(`[dev-db] Port ${PORT} is held by an unexpected process (pid ${pid}): ${cmd}`);
45 console.error(`[dev-db] Refusing to kill it. Free the port and retry.`);
46 process.exit(1);
47 }
48 console.log(`[dev-db] Reaping stale dev-db (pid ${pid})`);
49 execSync(`kill -KILL ${pid}`);
50 }
51 return true;
52}
53
54if (reapStaleDevDb()) {
55 // Give the kernel a beat to release the socket before we try to bind.

Callers 1

dev-db.tsFile · 0.85

Calls 2

errorMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected