From 304d7f239ae6e7b854a8da1124a919b7ba093b48 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sat, 7 Dec 2019 18:35:32 -0500 Subject: initial commit --- src/server/ApiManagers/DiagnosticManager.ts | 30 ------------------ src/server/ApiManagers/SearchManager.ts | 49 ++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 31 deletions(-) delete mode 100644 src/server/ApiManagers/DiagnosticManager.ts (limited to 'src/server/ApiManagers') diff --git a/src/server/ApiManagers/DiagnosticManager.ts b/src/server/ApiManagers/DiagnosticManager.ts deleted file mode 100644 index 104985481..000000000 --- a/src/server/ApiManagers/DiagnosticManager.ts +++ /dev/null @@ -1,30 +0,0 @@ -import ApiManager, { Registration } from "./ApiManager"; -import { Method } from "../RouteManager"; -import request = require('request-promise'); - -export default class DiagnosticManager extends ApiManager { - - protected initialize(register: Registration): void { - - register({ - method: Method.GET, - subscription: "/serverHeartbeat", - onValidation: ({ res }) => res.send(true) - }); - - register({ - method: Method.GET, - subscription: "/solrHeartbeat", - onValidation: async ({ res }) => { - try { - await request("http://localhost:8983"); - res.send({ running: true }); - } catch (e) { - res.send({ running: false }); - } - } - }); - - } - -} \ No newline at end of file diff --git a/src/server/ApiManagers/SearchManager.ts b/src/server/ApiManagers/SearchManager.ts index 7afecbb18..0e794fed6 100644 --- a/src/server/ApiManagers/SearchManager.ts +++ b/src/server/ApiManagers/SearchManager.ts @@ -4,11 +4,26 @@ import { Search } from "../Search"; const findInFiles = require('find-in-files'); import * as path from 'path'; import { pathToDirectory, Directory } from "./UploadManager"; +import { command_line, addBeforeExitHandler } from "../ActionUtilities"; +import request = require('request-promise'); +import { red, green, yellow, cyan } from "colors"; -export default class SearchManager extends ApiManager { +export class SearchManager extends ApiManager { protected initialize(register: Registration): void { + register({ + method: Method.GET, + subscription: "/startSolr", + onValidation: async ({ res }) => res.send((await SolrManager.SetRunning(true)) ? "Successfully started Solr!" : "Uh oh! Check the console for the error that occurred while starting Solr") + }); + + register({ + method: Method.GET, + subscription: "/stopSolr", + onValidation: async ({ res }) => res.send((await SolrManager.SetRunning(false)) ? "Successfully stopped Solr!" : "Uh oh! Check the console for the error that occurred while stopping Solr") + }); + register({ method: Method.GET, subscription: "/textsearch", @@ -46,4 +61,36 @@ export default class SearchManager extends ApiManager { } +} + +export namespace SolrManager { + + export async function initializeSolr() { + console.log(cyan("\nInspecting Solr status...")); + try { + await request("http://localhost:8983"); + console.log(green('Solr already running\n')); + } catch (e) { + console.log(cyan('Initializing Solr...')); + await SolrManager.SetRunning(true); + } finally { + addBeforeExitHandler(async () => SolrManager.SetRunning(false)); + } + } + + export async function SetRunning(status: boolean): Promise { + const args = status ? "start" : "stop -p 8983"; + console.log(`Solr management: trying to ${args}`); + try { + console.log(await command_line(`solr.cmd ${args}`, "../../solr-8.1.1/bin")); + return true; + } catch (e) { + console.log(red(`Solr management error: unable to ${args}`)); + if (status) { + process.exit(0); + } + return false; + } + } + } \ No newline at end of file -- cgit v1.2.3-70-g09d2