Moved sig event and stop message handling

- none of this should be inside the start message handling
- move to inside the start function, where it's clearer and makes more sense
This commit is contained in:
Hannah Wolfe 2020-08-07 20:14:31 +01:00
parent 31981d086b
commit 2289b7c0f7

View File

@ -105,6 +105,17 @@ GhostServer.prototype.start = function (externalApp) {
resolve(self);
});
});
function shutdown() {
// @TODO: await self.stop() here for consistency - but first we need stop to behave correctly
self.logStopMessages();
process.exit(0);
}
// ensure that Ghost exits correctly on Ctrl+C and SIGTERM
process
.removeAllListeners('SIGINT').on('SIGINT', shutdown)
.removeAllListeners('SIGTERM').on('SIGTERM', shutdown);
});
};
@ -145,33 +156,19 @@ GhostServer.prototype.hammertime = function () {
* ### Log Start Messages
*/
GhostServer.prototype.logStartMessages = function () {
let self = this;
logging.info(i18n.t('notices.httpServer.ghostIsRunningIn', {env: config.get('env')}));
// Startup & Shutdown messages
if (config.get('env') === 'production') {
logging.info(i18n.t('notices.httpServer.ghostIsRunningIn', {env: config.get('env')}));
logging.info(i18n.t('notices.httpServer.yourBlogIsAvailableOn', {url: urlUtils.urlFor('home', true)}));
logging.info(i18n.t('notices.httpServer.ctrlCToShutDown'));
} else {
logging.info(i18n.t('notices.httpServer.ghostIsRunningIn', {env: config.get('env')}));
logging.info(i18n.t('notices.httpServer.listeningOn', {
host: config.get('server').socket || config.get('server').host,
port: config.get('server').port
}));
logging.info(i18n.t('notices.httpServer.urlConfiguredAs', {url: urlUtils.urlFor('home', true)}));
logging.info(i18n.t('notices.httpServer.ctrlCToShutDown'));
}
function shutdown() {
// @TODO: await self.stop() here for consistency - but first we need stop to behave correctly
self.logStopMessages();
process.exit(0);
}
// ensure that Ghost exits correctly on Ctrl+C and SIGTERM
process
.removeAllListeners('SIGINT').on('SIGINT', shutdown)
.removeAllListeners('SIGTERM').on('SIGTERM', shutdown);
logging.info(i18n.t('notices.httpServer.ctrlCToShutDown'));
};
/**