From ed8cd8c72988efeb73339ec5eae7ff74f5a5ef4b Mon Sep 17 00:00:00 2001 From: ZGaetano Date: Sun, 3 May 2026 23:49:03 -0400 Subject: [PATCH] Add core MCP server implementation and Ross Talk protocol handler: health-check.ts --- src/health-check.ts | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/health-check.ts diff --git a/src/health-check.ts b/src/health-check.ts new file mode 100644 index 0000000..358e017 --- /dev/null +++ b/src/health-check.ts @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +/** + * Health check script for Docker container + * Exits with code 0 if healthy, 1 if unhealthy + */ + +import { WebSocket } from 'ws'; + +const HEALTH_CHECK_PORT = process.env.HEALTH_CHECK_PORT || '3000'; +const HEALTH_CHECK_TIMEOUT = 5000; + +async function healthCheck(): Promise { + try { + // Check if the main process is responsive + const healthUrl = `http://localhost:${HEALTH_CHECK_PORT}/health`; + + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), HEALTH_CHECK_TIMEOUT); + + try { + const response = await fetch(healthUrl, { + signal: controller.signal, + method: 'GET' + }); + + clearTimeout(timeoutId); + + if (response.ok) { + console.log('Health check passed'); + process.exit(0); + } else { + console.error(`Health check failed with status: ${response.status}`); + process.exit(1); + } + } catch (error) { + clearTimeout(timeoutId); + if (error instanceof Error && error.name === 'AbortError') { + console.error('Health check timed out'); + } else { + console.error('Health check failed:', error); + } + process.exit(1); + } + } catch (error) { + console.error('Health check error:', error); + process.exit(1); + } +} + +// Alternative simple health check - just verify the process is running +if (process.argv.includes('--simple')) { + console.log('Simple health check - process is running'); + process.exit(0); +} + +healthCheck();