From 811add80d3d8e1be79c17e26a5f8475fa3d0dd92 Mon Sep 17 00:00:00 2001 From: Matthew Lopez <73856503+MatthewL246@users.noreply.github.com> Date: Thu, 23 May 2024 20:59:24 -0400 Subject: [PATCH] Make all Node.js servers exit on SIGTERM This prevents the extra 10-second delay when restating the servers. --- patches/BOSS/exit-on-sigterm.patch | 12 ++++++++++ patches/account/exit-on-sigterm.patch | 14 +++++++++++ .../juxtaposition-ui/exit-on-sigterm.patch | 23 +++++++++++++++++++ ...stead-of-json-with-module-alias-hack.patch | 11 --------- patches/miiverse-api/exit-on-sigterm.patch | 19 +++++++++++++++ patches/website/exit-on-sigterm.patch | 12 ++++++++++ 6 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 patches/BOSS/exit-on-sigterm.patch create mode 100644 patches/account/exit-on-sigterm.patch create mode 100644 patches/juxtaposition-ui/exit-on-sigterm.patch create mode 100644 patches/miiverse-api/exit-on-sigterm.patch create mode 100644 patches/website/exit-on-sigterm.patch diff --git a/patches/BOSS/exit-on-sigterm.patch b/patches/BOSS/exit-on-sigterm.patch new file mode 100644 index 0000000..359836e --- /dev/null +++ b/patches/BOSS/exit-on-sigterm.patch @@ -0,0 +1,12 @@ +diff --git i/src/server.ts w/src/server.ts +index 5db5542..f4c1d47 100644 +--- i/src/server.ts ++++ w/src/server.ts +@@ -1,4 +1,7 @@ + process.title = 'Pretendo - BOSS'; ++process.on('SIGTERM', () => { ++ process.exit(0); ++}); + + import express from 'express'; + import morgan from 'morgan'; diff --git a/patches/account/exit-on-sigterm.patch b/patches/account/exit-on-sigterm.patch new file mode 100644 index 0000000..c8fc9ea --- /dev/null +++ b/patches/account/exit-on-sigterm.patch @@ -0,0 +1,14 @@ +diff --git i/src/server.ts w/src/server.ts +index 797c60e..97638db 100644 +--- i/src/server.ts ++++ w/src/server.ts +@@ -3,6 +3,9 @@ process.on('uncaughtException', (err, origin) => { + console.log(err); + console.log(origin); + }); ++process.on('SIGTERM', () => { ++ process.exit(0); ++}); + + import express from 'express'; + import morgan from 'morgan'; diff --git a/patches/juxtaposition-ui/exit-on-sigterm.patch b/patches/juxtaposition-ui/exit-on-sigterm.patch new file mode 100644 index 0000000..3f3ee2f --- /dev/null +++ b/patches/juxtaposition-ui/exit-on-sigterm.patch @@ -0,0 +1,23 @@ +diff --git i/src/server.js w/src/server.js +index be65907..ff45025 100644 +--- i/src/server.js ++++ w/src/server.js +@@ -1,6 +1,11 @@ + /* eslint-disable @typescript-eslint/explicit-function-return-type */ + /* eslint-disable @typescript-eslint/no-var-requires */ ++require('module-alias/register'); + process.title = 'Pretendo - Juxt-Web'; ++process.on('SIGTERM', () => { ++ process.exit(0); ++}); ++ + const express = require('express'); + const morgan = require('morgan'); + const cookieParser = require('cookie-parser'); +@@ -88,4 +93,4 @@ async function main() { + }); + } + +-main().catch(console.error); +\ No newline at end of file ++main().catch(console.error); diff --git a/patches/juxtaposition-ui/use-config-js-instead-of-json-with-module-alias-hack.patch b/patches/juxtaposition-ui/use-config-js-instead-of-json-with-module-alias-hack.patch index 2d2cc50..dbd9533 100644 --- a/patches/juxtaposition-ui/use-config-js-instead-of-json-with-module-alias-hack.patch +++ b/patches/juxtaposition-ui/use-config-js-instead-of-json-with-module-alias-hack.patch @@ -18,14 +18,3 @@ index 5132be7..177de10 100644 + "../../../../../../config.json": "/app/config.js" + } } -diff --git i/src/server.js w/src/server.js -index be65907..d378132 100644 ---- i/src/server.js -+++ w/src/server.js -@@ -1,5 +1,6 @@ - /* eslint-disable @typescript-eslint/explicit-function-return-type */ - /* eslint-disable @typescript-eslint/no-var-requires */ -+require('module-alias/register'); - process.title = 'Pretendo - Juxt-Web'; - const express = require('express'); - const morgan = require('morgan'); diff --git a/patches/miiverse-api/exit-on-sigterm.patch b/patches/miiverse-api/exit-on-sigterm.patch new file mode 100644 index 0000000..44fc12f --- /dev/null +++ b/patches/miiverse-api/exit-on-sigterm.patch @@ -0,0 +1,19 @@ +diff --git i/src/server.ts w/src/server.ts +index bc34398..46d42c7 100644 +--- i/src/server.ts ++++ w/src/server.ts +@@ -1,4 +1,7 @@ + process.title = 'Pretendo - Miiverse'; ++process.on('SIGTERM', () => { ++ process.exit(0); ++}); + + import express from 'express'; + import morgan from 'morgan'; +@@ -78,4 +81,4 @@ async function main(): Promise { + }); + } + +-main().catch(console.error); +\ No newline at end of file ++main().catch(console.error); diff --git a/patches/website/exit-on-sigterm.patch b/patches/website/exit-on-sigterm.patch new file mode 100644 index 0000000..460cbb5 --- /dev/null +++ b/patches/website/exit-on-sigterm.patch @@ -0,0 +1,12 @@ +diff --git i/src/server.js w/src/server.js +index b73bdde..04c714b 100644 +--- i/src/server.js ++++ w/src/server.js +@@ -1,4 +1,7 @@ + process.title = 'Pretendo - Website'; ++process.on('SIGTERM', () => { ++ process.exit(0); ++}); + + const express = require('express'); + const handlebars = require('express-handlebars');