From 7534cfb4e97b965e09c5a69e9113789de1ab74c1 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Mon, 19 Jul 2021 11:20:46 -0600 Subject: [PATCH] Catch the signals that are needed from systemd as well --- src/main.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 5e84b7d..2040389 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,11 +25,15 @@ if (!fs.existsSync(config.server.db_file)) { export var db: database = JSON.parse(fs.readFileSync(config.server.db_file, `utf-8`)); -process.on(`SIGINT`, () => { +function saveDB() { console.log(`Saving database`); fs.writeFileSync(config.server.db_file, JSON.stringify(db)); process.exit(0); -}); +}; + +process.on(`SIGINT`, saveDB); +process.on(`SIGTERM`, saveDB); +process.on(`uncaughtException`, saveDB); async function init() {