*Ensure the swarm properly shuts down and un-announces itself

This commit is contained in:
Derrick Hammer 2023-01-05 19:36:06 -05:00
parent d569c5fd8b
commit 6a41daff62
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 6 deletions

View File

@ -3,7 +3,7 @@ import { start as startRelay } from "./modules/relay.js";
import { start as startApp } from "./modules/app"; import { start as startApp } from "./modules/app";
import config from "./config.js"; import config from "./config.js";
import { loadPlugins } from "./modules/plugin.js"; import { loadPlugins } from "./modules/plugin.js";
import { start as startSwarm } from "./modules/swarm.js"; import { start as startSwarm, get as getSwarm } from "./modules/swarm.js";
import * as bip39 from "@scure/bip39"; import * as bip39 from "@scure/bip39";
import { wordlist } from "@scure/bip39/wordlists/english"; import { wordlist } from "@scure/bip39/wordlists/english";
@ -26,9 +26,11 @@ boot();
process.on("uncaughtException", function (err) { process.on("uncaughtException", function (err) {
console.log(`Caught exception: ${err.message} ${err.stack}`); console.log(`Caught exception: ${err.message} ${err.stack}`);
}); });
process.on("SIGINT", function () {
async function shutdown() {
await getSwarm().destroy();
process.exit(); process.exit();
}); }
process.on("SIGTERM", function () {
process.exit(); process.on("SIGINT", shutdown);
}); process.on("SIGTERM", shutdown);