feat: add daemon skeleton with lifecycle management

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
William Valentin
2026-02-02 20:56:45 -08:00
parent 4adf172c25
commit 70c3960527
4 changed files with 133 additions and 1 deletions
+30
View File
@@ -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';