diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-04 13:18:04 -0800 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2020-01-04 13:18:04 -0800 |
commit | ba1a85c4833820bc228779aa9187315d8b711268 (patch) | |
tree | f71cb70ae6f92b5895e573ca35a7369a11fea49a /src | |
parent | 987b512d2564710e5c5c7fd2eeff1914af8180dd (diff) |
added graceful kill option, rename
Diffstat (limited to 'src')
-rw-r--r-- | src/server/Session/session.ts | 14 | ||||
-rw-r--r-- | src/server/index.ts | 7 |
2 files changed, 13 insertions, 8 deletions
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<Repl> { + export async function initializeMonitorThread(): Promise<Repl> { 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<void> { + export async function initializeWorkerThread(work: Function): Promise<void> { 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("<img src='https://media.giphy.com/media/NGIfqtcS81qi4/giphy.gif' style='width:100%;height:100%;'/>"); - 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", |