From 4539ab22100adbbddeb7107412afedb6ee6ba185 Mon Sep 17 00:00:00 2001 From: WoLfulus Date: Wed, 23 Sep 2020 04:03:34 -0300 Subject: [PATCH] add process signal processing --- .editorconfig | 8 ++++++++ api/src/cli/commands/start.ts | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index d2cb980c62..52129378e7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,11 @@ trim_trailing_whitespace = true [{package.json,*.yml,*.yaml}] indent_style = space indent_size = 2 + +[Dockerfile] +indent_size = 2 +indent_style = tab + +[Makefile] +indent_size = 2 +indent_style = tab diff --git a/api/src/cli/commands/start.ts b/api/src/cli/commands/start.ts index f41bba2edc..f6fef91a43 100644 --- a/api/src/cli/commands/start.ts +++ b/api/src/cli/commands/start.ts @@ -1,4 +1,5 @@ import logger from '../../logger'; +import { Express } from 'express'; export default async function start() { const { default: env } = require('../../env'); @@ -6,11 +7,24 @@ export default async function start() { await validateDBConnection(); - const app = require('../../app').default; + const app: Express = require('../../app').default; const port = env.PORT; - app.listen(port, () => { + const server = app.listen(port, () => { logger.info(`Server started at port ${port}`); }); + + const signals: NodeJS.Signals[] = ['SIGHUP', 'SIGINT', 'SIGTERM']; + signals.forEach((signal) => { + process.on(signal, () => + server.close((err) => { + if (err) { + logger.error(err.message, { err }); + return; + } + logger.info('Server stopped.'); + }) + ); + }); }