express: Factor out common server shutdown logic
Also log when the HTTP server is about to be closed and when it is done closing.pull/4613/head
parent
ff19181cd1
commit
3e8c3e5789
|
@ -17,6 +17,14 @@ let serverName;
|
|||
|
||||
exports.server = null;
|
||||
|
||||
const closeServer = async () => {
|
||||
if (exports.server == null) return;
|
||||
logger.info('Closing HTTP server...');
|
||||
await util.promisify(exports.server.close.bind(exports.server))();
|
||||
exports.server = null;
|
||||
logger.info('HTTP server closed');
|
||||
};
|
||||
|
||||
exports.createServer = async () => {
|
||||
console.log('Report bugs at https://github.com/ether/etherpad-lite/issues');
|
||||
|
||||
|
@ -50,10 +58,7 @@ exports.createServer = async () => {
|
|||
};
|
||||
|
||||
exports.restartServer = async () => {
|
||||
if (exports.server) {
|
||||
console.log('Restarting express server');
|
||||
await util.promisify(exports.server.close).bind(exports.server)();
|
||||
}
|
||||
await closeServer();
|
||||
|
||||
const app = express(); // New syntax for express v3
|
||||
|
||||
|
@ -181,6 +186,5 @@ exports.restartServer = async () => {
|
|||
};
|
||||
|
||||
exports.shutdown = async (hookName, context) => {
|
||||
if (!exports.server) return;
|
||||
await util.promisify(exports.server.close).bind(exports.server)();
|
||||
await closeServer();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue