ShutdownManager (daemon/shutdown.ts)

codeoid · src/daemon/shutdown.ts · typescript · MIT
infra, tag:knn-classified

Manages graceful server shutdowns by executing registered cleanup hooks in reverse order within a strict grace period.

// Source: https://github.com/highflame-ai/codeoid | License: MIT | Copyright 2026 Codeoid
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Graceful shutdown with cleanup registry.
 *
 * Production pattern from Claude Code: gracefulShutdown.ts + cleanupRegistry.ts
 *
 * Cleanup functions are registered by components (store, sessions, frontends)
 * and run in reverse order on SIGTERM/SIGINT. A grace period (default 30s)
 * ensures in-flight work can finish before forced exit.
 */

type CleanupFn = () => Promise<void> | void;

interface ShutdownConfig {
  /** Grace period before forced exit. Default: 30_000ms. */
  gracePeriodMs: number;
  /** Custom logger. Default: console. */
  logger: Pick<Console, "log" | "error">;
}

const DEFAULT_CONFIG: ShutdownConfig = {
  gra

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key