2015-05-28 18:16:09 +03:00
|
|
|
// # Ghost Startup
|
|
|
|
// Orchestrates the startup of Ghost when run from command line.
|
2017-02-17 18:27:02 +03:00
|
|
|
|
2017-07-11 11:00:07 +03:00
|
|
|
var startTime = Date.now(),
|
|
|
|
debug = require('debug')('ghost:boot:index'),
|
2017-02-17 18:27:02 +03:00
|
|
|
ghost, express, logging, errors, utils, parentApp;
|
|
|
|
|
|
|
|
debug('First requires...');
|
|
|
|
|
|
|
|
ghost = require('./core');
|
|
|
|
|
|
|
|
debug('Required ghost');
|
|
|
|
|
|
|
|
express = require('express');
|
|
|
|
logging = require('./core/server/logging');
|
|
|
|
errors = require('./core/server/errors');
|
|
|
|
utils = require('./core/server/utils');
|
|
|
|
parentApp = express();
|
2016-06-03 11:06:18 +03:00
|
|
|
|
2016-10-03 11:33:14 +03:00
|
|
|
debug('Initialising Ghost');
|
2014-09-19 20:17:58 +04:00
|
|
|
ghost().then(function (ghostServer) {
|
2015-05-28 18:16:09 +03:00
|
|
|
// Mount our Ghost instance on our desired subdirectory path if it exists.
|
2016-09-12 14:53:04 +03:00
|
|
|
parentApp.use(utils.url.getSubdir(), ghostServer.rootApp);
|
2014-08-24 00:42:44 +04:00
|
|
|
|
2016-10-03 11:33:14 +03:00
|
|
|
debug('Starting Ghost');
|
2015-05-28 18:16:09 +03:00
|
|
|
// Let Ghost handle starting our server instance.
|
2016-11-07 17:25:29 +03:00
|
|
|
return ghostServer.start(parentApp).then(function afterStart() {
|
2017-07-11 11:00:07 +03:00
|
|
|
logging.info('Ghost boot', (Date.now() - startTime) / 1000 + 's');
|
|
|
|
|
2016-11-07 17:25:29 +03:00
|
|
|
// if IPC messaging is enabled, ensure ghost sends message to parent
|
|
|
|
// process on successful start
|
|
|
|
if (process.send) {
|
|
|
|
process.send({started: true});
|
|
|
|
}
|
|
|
|
});
|
2017-01-26 15:12:00 +03:00
|
|
|
}).catch(function (err) {
|
|
|
|
if (!errors.utils.isIgnitionError(err)) {
|
|
|
|
err = new errors.GhostError({err: err});
|
2016-11-07 17:25:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.send) {
|
2017-01-26 15:12:00 +03:00
|
|
|
process.send({started: false, error: err.message});
|
2016-11-07 17:25:29 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 15:12:00 +03:00
|
|
|
logging.error(err);
|
2016-11-07 17:25:29 +03:00
|
|
|
process.exit(-1);
|
2014-08-19 20:36:46 +04:00
|
|
|
});
|