add graceful violent interupt
This commit is contained in:
parent
54c4e91af8
commit
a1963cf491
2 changed files with 29 additions and 16 deletions
|
@ -6,9 +6,18 @@ import { socket_path } from "./src/lib/paths.ts";
|
|||
|
||||
await main();
|
||||
async function main() {
|
||||
const server = daemon_listen(socket_path());
|
||||
const enabled = new Map<string, Runner>();
|
||||
async function finish() {
|
||||
server.server.close();
|
||||
await Deno.remove(socket_path());
|
||||
for (const runner of enabled.values()) await runner.stop();
|
||||
Deno.exit(0);
|
||||
}
|
||||
Deno.addSignalListener("SIGINT", finish);
|
||||
console.log("listening to", socket_path());
|
||||
|
||||
for await (const { cmd, respond } of daemon_listen(socket_path())) {
|
||||
for await (const { cmd, respond } of server) {
|
||||
console.log("received", { cmd });
|
||||
|
||||
if (cmd.kind === "status") {
|
||||
|
@ -33,8 +42,7 @@ async function main() {
|
|||
|
||||
if (cmd.kind === "stop") {
|
||||
await respond(JSON.stringify("stopping, ++"));
|
||||
for (const runner of enabled.values()) await runner.stop();
|
||||
Deno.exit(0);
|
||||
await finish();
|
||||
}
|
||||
|
||||
await respond("unknown");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue