import type { LogContext } from '@rocicorp/logger';
import type { IncomingHttpHeaders } from 'node:http';
import type { EventEmitter } from 'stream';
import { type Subprocess, type Worker } from '../types/processes.ts';
import type { SingletonService } from './service.ts';
/**
 * * `user-facing` workers serve external requests and are the first to
 *   receive a `SIGTERM` or `SIGINT` signal for graceful shutdown.
 *
 * * `supporting` workers support `user-facing` workers and are sent
 *   the `SIGTERM` signal only after all `user-facing` workers have
 *   exited.
 *
 * For other kill signals, such as `SIGQUIT` and `SIGABRT`, all workers
 * are stopped without draining. `SIGQUIT` is used to represent an
 * intentional shutdown (for which draining is not beneficial), whereas
 * `SIGABRT` is used for unexpected process exits.
 */
export type WorkerType = 'user-facing' | 'supporting';
export declare const GRACEFUL_SHUTDOWN: readonly ["SIGTERM", "SIGINT"];
export declare const FORCEFUL_SHUTDOWN: readonly ["SIGQUIT", "SIGABRT"];
export declare const UNHANDLED_EXCEPTION_ERROR_CODE = 13;
/**
 * Handles readiness, termination signals, and coordination of graceful
 * shutdown.
 */
export declare class ProcessManager {
    #private;
    constructor(lc: LogContext, proc: EventEmitter);
    done(): Promise<void>;
    addSubprocess(proc: Subprocess, type: WorkerType, name: string): void;
    addWorker(worker: Worker, type: WorkerType, name: string): Worker;
    initializing(): string[];
    allWorkersReady(): Promise<void>;
    logErrorAndExit(err: unknown, name: string): void;
}
/**
 * Runs the specified services, stopping them on `SIGTERM` or `SIGINT` with
 * an optional {@link SingletonService.drain drain()}, or stopping them
 * without draining for `SIGQUIT`.
 *
 * @returns a Promise that resolves/rejects when any of the services stops/throws.
 */
export declare function runUntilKilled(lc: LogContext, parent: EventEmitter, ...services: SingletonService[]): Promise<void>;
export declare function exitAfter(run: () => Promise<void>): Promise<void>;
/**
 * The HeartbeatMonitor monitors the cadence heartbeats (e.g. "/keepalive"
 * health checks made to HttpServices) that signal that the server
 * should continue processing requests. When a configurable `stopInterval`
 * elapses without receiving these heartbeats, the monitor initiates a
 * graceful shutdown of the server. This works with common load balancing
 * frameworks such as AWS Elastic Load Balancing.
 *
 * The HeartbeatMonitor is **opt-in** in that it only kicks in after it
 * starts receiving keepalives.
 */
export declare class HeartbeatMonitor {
    #private;
    constructor(lc: LogContext, stopInterval?: number);
    onHeartbeat(reqHeaders: IncomingHttpHeaders): void;
    stop(): void;
}
//# sourceMappingURL=life-cycle.d.ts.map