-
-
Notifications
You must be signed in to change notification settings - Fork 814
Expand file tree
/
Copy pathshutdown.ts
More file actions
30 lines (24 loc) · 772 Bytes
/
shutdown.ts
File metadata and controls
30 lines (24 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { useNitroApp } from "../app.ts";
import type { ServerOptions } from "srvx";
export function resolveGracefulShutdownConfig(): ServerOptions["gracefulShutdown"] {
if (process.env.NITRO_SHUTDOWN_DISABLED) {
return false;
}
const timeoutMs = Number.parseInt(process.env.NITRO_SHUTDOWN_TIMEOUT ?? "", 10);
if (timeoutMs > 0) {
// srvx expects timeout in seconds
return { gracefulTimeout: timeoutMs / 1000 };
}
return undefined;
}
async function _shutdownHandler() {
try {
await useNitroApp().hooks?.callHook("close");
} catch (error) {
console.error("[nitro] Error running close hook:", error);
}
}
export function setupShutdownHooks() {
process.on("SIGTERM", _shutdownHandler);
process.on("SIGINT", _shutdownHandler);
}