diff options
Diffstat (limited to 'src/server/index.ts')
-rw-r--r-- | src/server/index.ts | 57 |
1 files changed, 5 insertions, 52 deletions
diff --git a/src/server/index.ts b/src/server/index.ts index 9bc3c7617..27e9a677b 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -3,7 +3,6 @@ import { GoogleApiServerUtils } from "./apis/google/GoogleApiServerUtils"; import * as mobileDetect from 'mobile-detect'; import * as path from 'path'; import { Database } from './database'; -const serverPort = 4321; import { DashUploadUtils } from './DashUploadUtils'; import RouteSubscriber from './RouteSubscriber'; import initializeServer from './server_initialization'; @@ -24,10 +23,7 @@ import GooglePhotosManager from "./ApiManagers/GooglePhotosManager"; import { Logger } from "./ProcessFactory"; import { yellow, red } from "colors"; import { Session } from "./Session/session"; -import { isMaster } from "cluster"; -import { execSync } from "child_process"; -import { Utils } from "../Utils"; -import { MessageStore } from "./Message"; +import { DashSessionAgent } from "./DashSession"; export const publicDirectory = path.resolve(__dirname, "public"); export const filesDirectory = path.resolve(publicDirectory, "files"); @@ -96,7 +92,7 @@ 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%;'/>"); - process.send!({ action: { message: "kill" } }); + sessionAgent.serverWorker.killSession(); } else { res.redirect("/home"); } @@ -136,7 +132,7 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }: * however, this becomes the logic invoked by a single worker thread spawned by * the main monitor (master) thread. */ -async function launchServer() { +export async function launchServer() { await log_execution({ startMessage: "\nstarting execution of preliminary functions", endMessage: "completed preliminary functions\n", @@ -145,50 +141,7 @@ async function launchServer() { await initializeServer(routeSetter); } -/** - * If we're the monitor (master) thread, we should launch the monitor logic for the session. - * Otherwise, we must be on a worker thread that was spawned *by* the monitor (master) thread, and thus - * our job should be to run the server. - */ -async function launchMonitoredSession() { - if (isMaster) { - const notificationRecipients = ["samuel_wilkins@brown.edu"]; - const signature = "-Dash Server Session Manager"; - const extensions = await Session.initializeMonitorThread({ - key: async (key, masterLog) => { - const content = `The key for this session (started @ ${new Date().toUTCString()}) is ${key}.\n\n${signature}`; - const failures = await Email.dispatchAll(notificationRecipients, "Server Termination Key", content); - if (failures) { - failures.map(({ recipient, error: { message } }) => masterLog(red(`dispatch failure @ ${recipient} (${yellow(message)})`))); - return false; - } - return true; - }, - crash: async ({ name, message, stack }, masterLog) => { - const body = [ - "You, as a Dash Administrator, are being notified of a server crash event. Here's what we know:", - `name:\n${name}`, - `message:\n${message}`, - `stack:\n${stack}`, - "The server is already restarting itself, but if you're concerned, use the Remote Desktop Connection to monitor progress.", - ].join("\n\n"); - const content = `${body}\n\n${signature}`; - const failures = await Email.dispatchAll(notificationRecipients, "Dash Web Server Crash", content); - if (failures) { - failures.map(({ recipient, error: { message } }) => masterLog(red(`dispatch failure @ ${recipient} (${yellow(message)})`))); - return false; - } - return true; - } - }); - extensions.addReplCommand("pull", [], () => execSync("git pull", { stdio: ["ignore", "inherit", "inherit"] })); - extensions.addReplCommand("solr", [/start|stop/g], args => SolrManager.SetRunning(args[0] === "start")); - } else { - const addExitHandler = await Session.initializeWorkerThread(launchServer); // server initialization delegated to worker - addExitHandler(() => Utils.Emit(WebSocket._socket, MessageStore.ConnectionTerminated, "Manual")); - } -} - +export const sessionAgent: Session.AppliedSessionAgent = new DashSessionAgent(); /** * If you're in development mode, you won't need to run a session. * The session spawns off new server processes each time an error is encountered, and doesn't @@ -196,7 +149,7 @@ async function launchMonitoredSession() { * So, the 'else' clause is exactly what we've always run when executing npm start. */ if (process.env.RELEASE) { - launchMonitoredSession(); + sessionAgent.launch(); } else { launchServer(); }
\ No newline at end of file |