feat: add daemon skeleton with lifecycle management
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { Lifecycle } from './lifecycle.js';
|
||||
import type { Config } from '../config/index.js';
|
||||
|
||||
export interface DaemonContext {
|
||||
config: Config;
|
||||
lifecycle: Lifecycle;
|
||||
}
|
||||
|
||||
export async function startDaemon(config: Config): Promise<DaemonContext> {
|
||||
const lifecycle = new Lifecycle();
|
||||
|
||||
// Register signal handlers
|
||||
const signalHandler = () => {
|
||||
lifecycle.shutdown().then(() => process.exit(0));
|
||||
};
|
||||
|
||||
process.on('SIGINT', signalHandler);
|
||||
process.on('SIGTERM', signalHandler);
|
||||
|
||||
lifecycle.onShutdown(async () => {
|
||||
process.off('SIGINT', signalHandler);
|
||||
process.off('SIGTERM', signalHandler);
|
||||
});
|
||||
|
||||
console.log('Flynn daemon started');
|
||||
|
||||
return { config, lifecycle };
|
||||
}
|
||||
|
||||
export { Lifecycle } from './lifecycle.js';
|
||||
Reference in New Issue
Block a user