From 0414ff4256ed2a82cd8a9955fe25424aa646132a Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Wed, 1 Aug 2018 23:11:27 +0300 Subject: [PATCH] fix Server is stopping only after second Ctrl-C #96 --- server/src/controllers/analytics_controller.ts | 2 +- server/src/index.ts | 6 +----- server/src/services/analytics_service.ts | 1 + server/src/services/process_service.ts | 3 +++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index 8e4014a..6e1a627 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -8,7 +8,7 @@ import { AnalyticsService, AnalyticsMessage } from '../services/analytics_servic const taskMap = {}; let nextTaskId = 0; -let analyticsService = undefined; +let analyticsService: AnalyticsService = undefined; function onTaskResult(taskResult: any) { diff --git a/server/src/index.ts b/server/src/index.ts index a094837..c77f47d 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -46,11 +46,7 @@ app .use(rootRouter.routes()) .use(rootRouter.allowedMethods()); -let server = app.listen(HASTIC_PORT, () => { +app.listen(HASTIC_PORT, () => { console.log(`Server is running on :${HASTIC_PORT}`); }); -ProcessService.registerExitHandler(() => { - console.log('Stopping server...'); - server.close(); -}) diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index f672f73..eb25bb6 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -70,6 +70,7 @@ export class AnalyticsService { console.log('Terminating analytics service...'); clearInterval(this._analyticsPinger); if(this._ipcPath !== null) { + console.log('Remove ipc path: ' + this._ipcPath); fs.unlinkSync(this._ipcPath); } this._requester.close(); diff --git a/server/src/services/process_service.ts b/server/src/services/process_service.ts index 9651293..1d9ce5b 100644 --- a/server/src/services/process_service.ts +++ b/server/src/services/process_service.ts @@ -1,4 +1,5 @@ + var exitHandlers = [] var exitHandled = false; @@ -19,6 +20,8 @@ function exitHandler(options, err) { for(let i = 0; i < exitHandlers.length; i++) { exitHandlers[i](); } + console.log('process exit'); + process.exit(); } //do something when app is closing