I'm trying to find a way to listen in Deno for the Docker SIGTERM signal to close my Oak server. I got this code from Oak website and it works fine when I call the controller.abort()
function, using setTimeout or an end-point. However, I want to call it when I got a SIGTERM signal from Docker and I cannot figure out how to listen for it.
const controller = new AbortController();
const app = new Application();
app.addEventListener("listen", ({ hostname, port }) => {
console.log(
bold("Start listening on ") + yellow(`${hostname}:${port}`),
);
});
// Utilise the signal from the controller
const { signal } = controller;
await app.listen({ hostname: "127.0.0.1", port: 8000, signal });
console.log(bold("Finished."));
I try to use this code from Deno GitHub discussions but also did not work
(() => {
for await (const _ of Deno.signal(Deno.Signal.SIGINT)) {
console.log("interrupt signal")
}
})()
(() => {
for await (const _ of Deno.signal(Deno.Signal.SIGQUIT)) {
console.log("quit signal")
}
})()
(() => {
for await (const _ of Deno.signal(Deno.Signal.SIGTERM)) {
console.log("terminate signal")
}
})()
I don't see either the logs and abort does not get called