diff --git a/run/core/deployment-orchestrator.ts b/run/core/deployment-orchestrator.ts index 279161e..14ee8bb 100644 --- a/run/core/deployment-orchestrator.ts +++ b/run/core/deployment-orchestrator.ts @@ -27,6 +27,22 @@ import { promisify } from 'node:util'; const execAsync = promisify(exec); +/** + * Find the PID of a process listening on a given port. + * Uses `ss` (Linux) to find the listener, returns null if no process found. + */ +async function getPortPid(port: number): Promise { + try { + const { stdout } = await execAsync( + `ss -tlnp sport = :${port} 2>/dev/null | grep -oP 'pid=\\K[0-9]+'` + ); + const pid = parseInt(stdout.trim().split('\n')[0], 10); + return isNaN(pid) ? null : pid; + } catch { + return null; + } +} + export interface DeploymentOrchestratorOptions { deploymentName: string; environment?: Environment;