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(),
|
2017-08-15 14:29:27 +03:00
|
|
|
debug = require('ghost-ignition').debug('boot:index'),
|
2018-07-27 16:19:39 +03:00
|
|
|
ghost, express, common, urlService, parentApp, config, GhostServer;
|
2017-02-17 18:27:02 +03:00
|
|
|
|
|
|
|
debug('First requires...');
|
|
|
|
|
|
|
|
ghost = require('./core');
|
|
|
|
|
|
|
|
debug('Required ghost');
|
|
|
|
|
|
|
|
express = require('express');
|
2018-07-27 16:19:39 +03:00
|
|
|
GhostServer = require('./core/server/ghost-server');
|
|
|
|
config = require('./core/server/config');
|
2018-07-27 16:34:31 +03:00
|
|
|
common = require('./core/server/lib/common');
|
2017-12-11 21:14:05 +03:00
|
|
|
urlService = require('./core/server/services/url');
|
2017-02-17 18:27:02 +03:00
|
|
|
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.
|
2017-12-11 21:14:05 +03:00
|
|
|
parentApp.use(urlService.utils.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.
|
2018-07-27 16:19:39 +03:00
|
|
|
return ghostServer.start(parentApp)
|
|
|
|
.then(function afterStart() {
|
|
|
|
common.logging.info('Ghost boot', (Date.now() - startTime) / 1000 + 's');
|
|
|
|
|
|
|
|
if (!config.get('maintenance:enabled')) {
|
|
|
|
return GhostServer.announceServerStart();
|
|
|
|
}
|
|
|
|
});
|
2017-01-26 15:12:00 +03:00
|
|
|
}).catch(function (err) {
|
2017-12-12 00:47:46 +03:00
|
|
|
if (!common.errors.utils.isIgnitionError(err)) {
|
2018-06-04 13:12:37 +03:00
|
|
|
err = new common.errors.GhostError({message: err.message, err: err});
|
2016-11-07 17:25:29 +03:00
|
|
|
}
|
|
|
|
|
2018-07-27 16:19:39 +03:00
|
|
|
return GhostServer.announceServerStopped(err)
|
|
|
|
.finally(() => {
|
|
|
|
common.logging.error(err);
|
2018-08-14 14:55:49 +03:00
|
|
|
setTimeout(() => {
|
|
|
|
process.exit(-1);
|
|
|
|
}, 100);
|
2018-07-27 16:19:39 +03:00
|
|
|
});
|
2014-08-19 20:36:46 +04:00
|
|
|
});
|