#!/usr/bin/env node /** * Local healthcheck for peardock server process supervision. * Checks Docker socket reachability (same as server dependency). * Exit 0 = healthy, 1 = unhealthy. * * Usage: node scripts/healthcheck.js * Docker HEALTHCHECK / systemd ExecStartPost / k8s probe compatible. */ import Docker from 'dockerode' const timeoutMs = Number(process.env.HEALTHCHECK_TIMEOUT_MS) || 5000 const docker = new Docker({ socketPath: process.env.DOCKER_SOCKET || '/var/run/docker.sock' }) const timer = setTimeout(() => { console.error('healthcheck: timeout') process.exit(1) }, timeoutMs) try { await docker.ping() clearTimeout(timer) console.log('ok docker') process.exit(0) } catch (err) { clearTimeout(timer) console.error('healthcheck failed:', err.message) process.exit(1) }