chore: Graceful server shutdown, closes #2507
This commit is contained in:
parent
3dfd336f59
commit
2024c6e64f
|
@ -3,6 +3,9 @@ declare var process: {
|
|||
exit: (code?: number) => void,
|
||||
cwd: () => string,
|
||||
argv: Array<string>,
|
||||
on: (event: string, listener: Function) => void,
|
||||
once: (event: string, listener: Function) => void,
|
||||
off: (event: string, listener: Function) => void,
|
||||
env: {
|
||||
[string]: string,
|
||||
},
|
||||
|
|
|
@ -155,6 +155,7 @@
|
|||
"socket.io": "^2.4.0",
|
||||
"socket.io-redis": "^5.4.0",
|
||||
"socketio-auth": "^0.1.1",
|
||||
"stoppable": "^1.1.0",
|
||||
"string-replace-to-array": "^1.0.3",
|
||||
"styled-components": "^5.2.3",
|
||||
"styled-components-breakpoint": "^2.1.1",
|
||||
|
@ -212,4 +213,4 @@
|
|||
"js-yaml": "^3.13.1"
|
||||
},
|
||||
"version": "0.58.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import compress from "koa-compress";
|
|||
import helmet from "koa-helmet";
|
||||
import logger from "koa-logger";
|
||||
import { uniq } from "lodash";
|
||||
import stoppable from "stoppable";
|
||||
import throng from "throng";
|
||||
import "./sentry";
|
||||
import services from "./services";
|
||||
|
@ -34,9 +35,9 @@ const serviceNames = uniq(
|
|||
.map((service) => service.trim())
|
||||
);
|
||||
|
||||
async function start() {
|
||||
async function start(id, disconnect) {
|
||||
const app = new Koa();
|
||||
const server = http.createServer(app.callback());
|
||||
const server = stoppable(http.createServer(app.callback()));
|
||||
const httpLogger = debug("http");
|
||||
const log = debug("server");
|
||||
|
||||
|
@ -65,6 +66,14 @@ async function start() {
|
|||
});
|
||||
|
||||
server.listen(env.PORT || "3000");
|
||||
|
||||
process.once("SIGTERM", shutdown);
|
||||
process.once("SIGINT", shutdown);
|
||||
|
||||
function shutdown() {
|
||||
console.log("\n> Stopping server");
|
||||
server.stop(disconnect);
|
||||
}
|
||||
}
|
||||
|
||||
throng({
|
||||
|
|
|
@ -12413,6 +12413,11 @@ stealthy-require@^1.1.1:
|
|||
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
|
||||
integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=
|
||||
|
||||
stoppable@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/stoppable/-/stoppable-1.1.0.tgz#32da568e83ea488b08e4d7ea2c3bcc9d75015d5b"
|
||||
integrity sha512-KXDYZ9dszj6bzvnEMRYvxgeTHU74QBFL54XKtP3nyMuJ81CFYtABZ3bAzL2EdFUaEwJOBOgENyFj3R7oTzDyyw==
|
||||
|
||||
stream-browserify@^2.0.1:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.2.tgz#87521d38a44aa7ee91ce1cd2a47df0cb49dd660b"
|
||||
|
|
Reference in New Issue