mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
✨ ghost startup ipc messaging (#7678)
no issue - add ipc messaging to ghost on startup success/error - works with Ghost-CLI to ensure improve process management
This commit is contained in:
parent
bae0de6cd5
commit
b3f09347e4
@ -7,7 +7,6 @@ var debug = require('debug')('ghost:server'),
|
||||
path = require('path'),
|
||||
_ = require('lodash'),
|
||||
errors = require('./errors'),
|
||||
logging = require('./logging'),
|
||||
config = require('./config'),
|
||||
i18n = require('./i18n'),
|
||||
moment = require('moment');
|
||||
@ -46,7 +45,7 @@ GhostServer.prototype.start = function (externalApp) {
|
||||
permissions: '660'
|
||||
};
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (config.get('server').hasOwnProperty('socket')) {
|
||||
socketConfig = config.get('server').socket;
|
||||
|
||||
@ -75,21 +74,23 @@ GhostServer.prototype.start = function (externalApp) {
|
||||
}
|
||||
|
||||
self.httpServer.on('error', function (error) {
|
||||
var ghostError;
|
||||
|
||||
if (error.errno === 'EADDRINUSE') {
|
||||
logging.error(new errors.GhostError({
|
||||
ghostError = new errors.GhostError({
|
||||
message: i18n.t('errors.httpServer.addressInUse.error'),
|
||||
context: i18n.t('errors.httpServer.addressInUse.context', {port: config.get('server').port}),
|
||||
help: i18n.t('errors.httpServer.addressInUse.help')
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
logging.error(new errors.GhostError({
|
||||
ghostError = new errors.GhostError({
|
||||
message: i18n.t('errors.httpServer.otherError.error', {errorNumber: error.errno}),
|
||||
context: i18n.t('errors.httpServer.otherError.context'),
|
||||
help: i18n.t('errors.httpServer.otherError.help')
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
process.exit(-1);
|
||||
reject(ghostError);
|
||||
});
|
||||
self.httpServer.on('connection', self.connection.bind(self));
|
||||
self.httpServer.on('listening', function () {
|
||||
|
22
index.js
22
index.js
@ -15,8 +15,22 @@ ghost().then(function (ghostServer) {
|
||||
|
||||
debug('Starting Ghost');
|
||||
// Let Ghost handle starting our server instance.
|
||||
ghostServer.start(parentApp);
|
||||
}).catch(function (err) {
|
||||
logging.error(new errors.GhostError({err: err}));
|
||||
process.exit(0);
|
||||
return ghostServer.start(parentApp).then(function afterStart() {
|
||||
// if IPC messaging is enabled, ensure ghost sends message to parent
|
||||
// process on successful start
|
||||
if (process.send) {
|
||||
process.send({started: true});
|
||||
}
|
||||
});
|
||||
}).catch(function (error) {
|
||||
if (!(error instanceof errors.GhostError)) {
|
||||
error = new errors.GhostError({err: error});
|
||||
}
|
||||
|
||||
if (process.send) {
|
||||
process.send({started: false, error: error.message});
|
||||
}
|
||||
|
||||
logging.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user