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