Gracefully exit on SIGTERM/SIGKILL/SIGQUIT
This commit is contained in:
parent
96c28027ef
commit
6afd222515
|
@ -13,6 +13,7 @@
|
||||||
"@hapi/inert": "^6.0.4",
|
"@hapi/inert": "^6.0.4",
|
||||||
"@hapi/vision": "^6.1.0",
|
"@hapi/vision": "^6.1.0",
|
||||||
"cheerio": "^1.0.0-rc.10",
|
"cheerio": "^1.0.0-rc.10",
|
||||||
|
"exiting": "^6.0.1",
|
||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"hpagent": "^0.1.2",
|
"hpagent": "^0.1.2",
|
||||||
"pug": "^3.0.2"
|
"pug": "^3.0.2"
|
||||||
|
@ -1224,6 +1225,21 @@
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/exiting": {
|
||||||
|
"version": "6.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/exiting/-/exiting-6.0.1.tgz",
|
||||||
|
"integrity": "sha512-0kUQkyWTMJUZ2wKkxjducVojsL5vtDxw26q9sd07SwyWZswbHOrWN9Bs2jk9uXffatsGp2QP5tmQUYXiPi1Z2A==",
|
||||||
|
"dependencies": {
|
||||||
|
"@hapi/bounce": "^2.0.0",
|
||||||
|
"@hapi/hoek": "^9.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.13.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@hapi/hapi": ">=17.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/fill-range": {
|
"node_modules/fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
||||||
|
@ -4359,6 +4375,15 @@
|
||||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"exiting": {
|
||||||
|
"version": "6.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/exiting/-/exiting-6.0.1.tgz",
|
||||||
|
"integrity": "sha512-0kUQkyWTMJUZ2wKkxjducVojsL5vtDxw26q9sd07SwyWZswbHOrWN9Bs2jk9uXffatsGp2QP5tmQUYXiPi1Z2A==",
|
||||||
|
"requires": {
|
||||||
|
"@hapi/bounce": "^2.0.0",
|
||||||
|
"@hapi/hoek": "^9.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"fill-range": {
|
"fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
"@hapi/inert": "^6.0.4",
|
"@hapi/inert": "^6.0.4",
|
||||||
"@hapi/vision": "^6.1.0",
|
"@hapi/vision": "^6.1.0",
|
||||||
"cheerio": "^1.0.0-rc.10",
|
"cheerio": "^1.0.0-rc.10",
|
||||||
|
"exiting": "^6.0.1",
|
||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"hpagent": "^0.1.2",
|
"hpagent": "^0.1.2",
|
||||||
"pug": "^3.0.2"
|
"pug": "^3.0.2"
|
||||||
|
|
15
src/index.ts
15
src/index.ts
|
@ -1,13 +1,13 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import Hapi = require('@hapi/hapi');
|
import Hapi = require('@hapi/hapi');
|
||||||
|
const Exiting = require('exiting');
|
||||||
import Path = require('path');
|
import Path = require('path');
|
||||||
import { handleAlbum, handleGallery, handleMedia, handleTag, handleUser } from './handlers';
|
import { handleAlbum, handleGallery, handleMedia, handleTag, handleUser } from './handlers';
|
||||||
|
|
||||||
import CONFIG from './config';
|
import CONFIG from './config';
|
||||||
|
|
||||||
const init = async () => {
|
const server = Hapi.server({
|
||||||
const server = Hapi.server({
|
|
||||||
port: CONFIG.port,
|
port: CONFIG.port,
|
||||||
host: CONFIG.host,
|
host: CONFIG.host,
|
||||||
address: CONFIG.address,
|
address: CONFIG.address,
|
||||||
|
@ -16,7 +16,14 @@ const init = async () => {
|
||||||
relativeTo: Path.join(__dirname, 'static')
|
relativeTo: Path.join(__dirname, 'static')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
server.events.on('stop', () => {
|
||||||
|
console.log('Server stopped.');
|
||||||
|
});
|
||||||
|
|
||||||
|
const manager = Exiting.createManager(server);
|
||||||
|
|
||||||
|
const init = async () => {
|
||||||
await server.register(require('@hapi/vision'));
|
await server.register(require('@hapi/vision'));
|
||||||
await server.register(require('@hapi/inert'));
|
await server.register(require('@hapi/inert'));
|
||||||
|
|
||||||
|
@ -62,7 +69,7 @@ const init = async () => {
|
||||||
handler: handleGallery,
|
handler: handleGallery,
|
||||||
});
|
});
|
||||||
|
|
||||||
await server.start();
|
await manager.start();
|
||||||
console.log('Server running on %s', server.info.uri);
|
console.log('Server running on %s', server.info.uri);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue