diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-12-12 11:05:36 -0500 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-12-12 11:05:36 -0500 |
commit | 85e7ca251beefa0b5417c8e6e6d28f9aaa5d886c (patch) | |
tree | d0bf5df3297e046061efa5e28ab70c521103644d /src | |
parent | b55ce381c905e87421bf011f5cd0cf423f858bb8 (diff) |
killport
Diffstat (limited to 'src')
-rw-r--r-- | src/server/ChildProcessUtilities/daemon/session.ts | 25 | ||||
-rw-r--r-- | src/typings/index.d.ts | 1 |
2 files changed, 5 insertions, 21 deletions
diff --git a/src/server/ChildProcessUtilities/daemon/session.ts b/src/server/ChildProcessUtilities/daemon/session.ts index 9e082e665..41eb6976e 100644 --- a/src/server/ChildProcessUtilities/daemon/session.ts +++ b/src/server/ChildProcessUtilities/daemon/session.ts @@ -6,7 +6,7 @@ import { MailOptions } from "nodemailer/lib/json-transport"; import { writeFileSync, appendFileSync, existsSync, mkdirSync } from "fs"; import { resolve } from 'path'; import { ChildProcess, exec } from "child_process"; -import { ProcessFactory } from "../ProcessFactory"; +import * as killport from "kill-port"; const identifier = yellow("__daemon__:"); @@ -79,6 +79,7 @@ async function listen() { restarting = true; addLogEntry("Detected a server crash", red); current_backup?.kill(); + await killport(1050, 'tcp'); await log_execution({ startMessage: identifier + " Sending crash notification email", endMessage: ({ error, result }) => { @@ -88,26 +89,8 @@ async function listen() { action: async () => notify(error || "Hmm, no error to report..."), color: cyan }); - await log_execution({ - startMessage: identifier + " Initiating server restart", - endMessage: ({ result, error }) => { - const success = error === null && result !== undefined; - return identifier + success ? " Child process spawned..." : ` An error occurred while attempting to restart the server:\n${error}`; - }, - action: async () => { - return new Promise<void>(resolve => { - exec('"C:\\Program Files\\Git\\git-bash.exe" -c "npm run start-release"', err => { - if (err) { - identifiedLog(err.message); - return; - } - resolve(); - }); - - }); - }, - color: green - }); + identifiedLog(green("Initiating server restart...")); + current_backup = exec('"C:\\Program Files\\Git\\git-bash.exe" -c "npm run start-release"', err => identifiedLog(err?.message || "Previous server process exited.")); writeLocalPidLog("server", `${(current_backup?.pid ?? -2) + 1} created ${timestamp()}`); } else { identifiedLog(yellow(`Callback ignored because restarting already initiated ${timestamp()}`)); diff --git a/src/typings/index.d.ts b/src/typings/index.d.ts index 9e8ace962..674278126 100644 --- a/src/typings/index.d.ts +++ b/src/typings/index.d.ts @@ -2,6 +2,7 @@ declare module 'googlephotos'; declare module 'react-image-lightbox-with-rotate'; +declare module 'kill-port'; declare module '@react-pdf/renderer' { import * as React from 'react'; |