@leelaing/service-manager
v0.1.0
Published
Reusable Node.js service lifecycle, process, port, and health-check management.
Maintainers
Readme
@leelaing/service-manager
Reusable Node.js service lifecycle, process, port, and health-check management.
Install
npm install @leelaing/service-managerExample
import { createService } from '@leelaing/service-manager';
const whisper = createService({
name: 'Whisper',
command: {
command: 'python3',
args: ['server.py', '--port', '8178'],
cwd: '/path/to/whisper-service',
},
port: { port: 8178 },
health: { url: 'http://127.0.0.1:8178/health' },
});
await whisper.start();
console.log(await whisper.status());
await whisper.restart();
await whisper.stop();API
createService(options)
Creates a ServiceManager instance.
Lifecycle
start()starts the configured child process and waits for readiness.stop()sendsSIGTERM, then escalates toSIGKILLafter the configured timeout.restart()stops and starts the service.status()reports process, port, health, PID, exit, and timing state.
Readiness helpers
isPortOpen({ port, host, timeoutMs })checkHttpHealth({ url, timeoutMs, acceptedStatusCodes })
When both a port and an HTTP health check are configured, both must succeed before start() resolves.
Events
ServiceManager emits:
statestartstopexitstdoutstderrerror
Recent stdout/stderr entries are also available through service.logs.
Development
npm install
npm startRun all checks with:
npm run checkLicense
MIT
