Add core MCP server implementation and Ross Talk protocol handler: health-check.ts
This commit is contained in:
parent
f269e7a638
commit
ed8cd8c729
1 changed files with 57 additions and 0 deletions
57
src/health-check.ts
Normal file
57
src/health-check.ts
Normal file
|
|
@ -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<void> {
|
||||||
|
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();
|
||||||
Loading…
Reference in a new issue