Skip to content

Commit

Permalink
✨ ghost startup ipc messaging (#7678)
Browse files Browse the repository at this point in the history
no issue

- add ipc messaging to ghost on startup success/error
- works with Ghost-CLI to ensure improve process management
  • Loading branch information
acburdine authored and kirrg001 committed Nov 7, 2016
1 parent bae0de6 commit b3f0934
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
15 changes: 8 additions & 7 deletions core/server/ghost-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 () {
Expand Down
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit b3f0934

Please sign in to comment.