mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05: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
2 changed files with 26 additions and 11 deletions
|
@ -7,7 +7,6 @@ var debug = require('debug')('ghost:server'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
errors = require('./errors'),
|
errors = require('./errors'),
|
||||||
logging = require('./logging'),
|
|
||||||
config = require('./config'),
|
config = require('./config'),
|
||||||
i18n = require('./i18n'),
|
i18n = require('./i18n'),
|
||||||
moment = require('moment');
|
moment = require('moment');
|
||||||
|
@ -46,7 +45,7 @@ GhostServer.prototype.start = function (externalApp) {
|
||||||
permissions: '660'
|
permissions: '660'
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve, reject) {
|
||||||
if (config.get('server').hasOwnProperty('socket')) {
|
if (config.get('server').hasOwnProperty('socket')) {
|
||||||
socketConfig = config.get('server').socket;
|
socketConfig = config.get('server').socket;
|
||||||
|
|
||||||
|
@ -75,21 +74,23 @@ GhostServer.prototype.start = function (externalApp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.httpServer.on('error', function (error) {
|
self.httpServer.on('error', function (error) {
|
||||||
|
var ghostError;
|
||||||
|
|
||||||
if (error.errno === 'EADDRINUSE') {
|
if (error.errno === 'EADDRINUSE') {
|
||||||
logging.error(new errors.GhostError({
|
ghostError = new errors.GhostError({
|
||||||
message: i18n.t('errors.httpServer.addressInUse.error'),
|
message: i18n.t('errors.httpServer.addressInUse.error'),
|
||||||
context: i18n.t('errors.httpServer.addressInUse.context', {port: config.get('server').port}),
|
context: i18n.t('errors.httpServer.addressInUse.context', {port: config.get('server').port}),
|
||||||
help: i18n.t('errors.httpServer.addressInUse.help')
|
help: i18n.t('errors.httpServer.addressInUse.help')
|
||||||
}));
|
});
|
||||||
} else {
|
} else {
|
||||||
logging.error(new errors.GhostError({
|
ghostError = new errors.GhostError({
|
||||||
message: i18n.t('errors.httpServer.otherError.error', {errorNumber: error.errno}),
|
message: i18n.t('errors.httpServer.otherError.error', {errorNumber: error.errno}),
|
||||||
context: i18n.t('errors.httpServer.otherError.context'),
|
context: i18n.t('errors.httpServer.otherError.context'),
|
||||||
help: i18n.t('errors.httpServer.otherError.help')
|
help: i18n.t('errors.httpServer.otherError.help')
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
process.exit(-1);
|
reject(ghostError);
|
||||||
});
|
});
|
||||||
self.httpServer.on('connection', self.connection.bind(self));
|
self.httpServer.on('connection', self.connection.bind(self));
|
||||||
self.httpServer.on('listening', function () {
|
self.httpServer.on('listening', function () {
|
||||||
|
|
22
index.js
22
index.js
|
@ -15,8 +15,22 @@ ghost().then(function (ghostServer) {
|
||||||
|
|
||||||
debug('Starting Ghost');
|
debug('Starting Ghost');
|
||||||
// Let Ghost handle starting our server instance.
|
// Let Ghost handle starting our server instance.
|
||||||
ghostServer.start(parentApp);
|
return ghostServer.start(parentApp).then(function afterStart() {
|
||||||
}).catch(function (err) {
|
// if IPC messaging is enabled, ensure ghost sends message to parent
|
||||||
logging.error(new errors.GhostError({err: err}));
|
// process on successful start
|
||||||
process.exit(0);
|
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…
Add table
Reference in a new issue