From ba1a85c4833820bc228779aa9187315d8b711268 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sat, 4 Jan 2020 13:18:04 -0800 Subject: added graceful kill option, rename --- src/server/Session/session.ts | 14 +++++++++----- src/server/index.ts | 7 ++++--- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/server/Session/session.ts b/src/server/Session/session.ts index d1d7aab87..789a40c42 100644 --- a/src/server/Session/session.ts +++ b/src/server/Session/session.ts @@ -30,7 +30,7 @@ export namespace Session { * Validates and reads the configuration file, accordingly builds a child process factory * and spawns off an initial process that will respawn as predecessors die. */ - export async function initializeMaster(): Promise { + export async function initializeMonitorThread(): Promise { let activeWorker: Worker; // read in configuration .json file only once, in the master thread @@ -101,9 +101,13 @@ export namespace Session { setupMaster({ silent: !showServerOutput }); // attempts to kills the active worker ungracefully - const tryKillActiveWorker = (): boolean => { + const tryKillActiveWorker = (strict = true): boolean => { if (activeWorker && !activeWorker.isDead()) { - activeWorker.process.kill(); + if (strict) { + activeWorker.process.kill(); + } else { + activeWorker.kill(); + } return true; } return false; @@ -129,7 +133,7 @@ export namespace Session { switch (message) { case "kill": console.log(masterIdentifier, red("An authorized user has ended the server session from the /kill route")); - tryKillActiveWorker(); + tryKillActiveWorker(false); process.exit(0); case "notify_crash": const { error: { name, message, stack } } = args; @@ -179,7 +183,7 @@ export namespace Session { * email if the server encounters an uncaught exception or if the server cannot be reached. * @param work the function specifying the work to be done by each worker thread */ - export async function initializeWorker(work: Function): Promise { + export async function initializeWorkerThread(work: Function): Promise { let listening = false; // notify master thread (which will log update in the console) of initialization via IPC diff --git a/src/server/index.ts b/src/server/index.ts index 7eb8b12be..4400687d8 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -94,7 +94,8 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }: secureHandler: ({ req, res }) => { if (req.params.key === process.env.session_key) { res.send(""); - setTimeout(() => process.send!({ action: { message: "kill" } }), 1000 * 5); + // setTimeout(() => process.send!({ action: { message: "kill" } }), 1000 * 5); + process.send!({ action: { message: "kill" } }); } else { res.redirect("/home"); } @@ -132,11 +133,11 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }: * Thread dependent session initialization */ if (isMaster) { - Session.initializeMaster().then(({ registerCommand }) => { + Session.initializeMonitorThread().then(({ registerCommand }) => { registerCommand("pull", [], () => execSync("git pull", { stdio: ["ignore", "inherit", "inherit"] })); }); } else { - Session.initializeWorker(async () => { + Session.initializeWorkerThread(async () => { await log_execution({ startMessage: "\nstarting execution of preliminary functions", endMessage: "completed preliminary functions\n", -- cgit v1.2.3-70-g09d2