2021-02-19 14:51:01 +03:00
|
|
|
// The Ghost Boot Sequence
|
|
|
|
// -----------------------
|
|
|
|
// - This is intentionally one big file at the moment, so that we don't have to follow boot logic all over the place
|
|
|
|
// - This file is FULL of debug statements so we can see timings for the various steps because the boot needs to be as fast as possible
|
|
|
|
// - As we manage to break the codebase down into distinct components for e.g. the frontend, their boot logic can be offloaded to them
|
|
|
|
// - app.js is separate as the first example of each component having it's own app.js file colocated with it, instead of inside of server/web
|
2021-06-28 12:04:59 +03:00
|
|
|
//
|
|
|
|
// IMPORTANT:
|
|
|
|
// ----------
|
|
|
|
// The only global requires here should be overrides + debug so we can monitor timings with DEBUG = ghost: boot * node ghost
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
require('./server/overrides');
|
2021-06-15 19:01:22 +03:00
|
|
|
const debug = require('@tryghost/debug')('boot');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
// END OF GLOBAL REQUIRES
|
|
|
|
|
2021-02-23 14:49:59 +03:00
|
|
|
/**
|
|
|
|
* Helper class to create consistent log messages
|
2021-06-28 12:04:59 +03:00
|
|
|
*/
|
|
|
|
class BootLogger {
|
2021-10-12 16:29:10 +03:00
|
|
|
constructor(logging, metrics, startTime) {
|
2021-02-16 14:54:19 +03:00
|
|
|
this.logging = logging;
|
2021-10-12 16:29:10 +03:00
|
|
|
this.metrics = metrics;
|
2021-02-16 14:54:19 +03:00
|
|
|
this.startTime = startTime;
|
|
|
|
}
|
|
|
|
log(message) {
|
|
|
|
let {logging, startTime} = this;
|
|
|
|
logging.info(`Ghost ${message} in ${(Date.now() - startTime) / 1000}s`);
|
|
|
|
}
|
2022-03-24 12:16:19 +03:00
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {number} [initialTime]
|
|
|
|
*/
|
|
|
|
metric(name, initialTime) {
|
2021-10-12 16:29:10 +03:00
|
|
|
let {metrics, startTime} = this;
|
2022-03-24 12:16:19 +03:00
|
|
|
|
|
|
|
if (!initialTime) {
|
|
|
|
initialTime = startTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
metrics.metric(name, Date.now() - initialTime);
|
2021-10-12 16:29:10 +03:00
|
|
|
}
|
2021-02-16 14:54:19 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 14:49:59 +03:00
|
|
|
/**
|
|
|
|
* Helper function to handle sending server ready notifications
|
2021-06-28 12:04:59 +03:00
|
|
|
* @param {string} [error]
|
2021-02-23 14:49:59 +03:00
|
|
|
*/
|
|
|
|
function notifyServerReady(error) {
|
|
|
|
const notify = require('./server/notify');
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
debug('Notifying server ready (error)');
|
|
|
|
notify.notifyServerReady(error);
|
|
|
|
} else {
|
|
|
|
debug('Notifying server ready (success)');
|
|
|
|
notify.notifyServerReady();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
/**
|
|
|
|
* Get the Database into a ready state
|
|
|
|
* - DatabaseStateManager handles doing all this for us
|
2021-06-28 12:04:59 +03:00
|
|
|
*
|
|
|
|
* @param {object} options
|
|
|
|
* @param {object} options.config
|
2021-02-19 14:51:01 +03:00
|
|
|
*/
|
2021-12-14 14:22:39 +03:00
|
|
|
async function initDatabase({config}) {
|
2021-02-19 14:51:01 +03:00
|
|
|
const DatabaseStateManager = require('./server/data/db/state-manager');
|
|
|
|
const dbStateManager = new DatabaseStateManager({knexMigratorFilePath: config.get('paths:appRoot')});
|
2021-12-14 14:22:39 +03:00
|
|
|
await dbStateManager.makeReady();
|
2022-01-18 12:10:31 +03:00
|
|
|
|
|
|
|
const databaseInfo = require('./server/data/db/info');
|
|
|
|
await databaseInfo.init();
|
2021-02-19 14:51:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-23 14:49:59 +03:00
|
|
|
* Core is intended to be all the bits of Ghost that are fundamental and we can't do anything without them!
|
2021-02-19 14:51:01 +03:00
|
|
|
* (There's more to do to make this true)
|
2021-06-28 12:04:59 +03:00
|
|
|
* @param {object} options
|
|
|
|
* @param {object} options.ghostServer
|
2021-07-27 13:07:11 +03:00
|
|
|
* @param {object} options.config
|
2021-11-16 17:44:14 +03:00
|
|
|
* @param {object} options.bootLogger
|
2021-11-22 09:51:54 +03:00
|
|
|
* @param {boolean} options.frontend
|
2021-02-19 14:51:01 +03:00
|
|
|
*/
|
2021-11-22 09:51:54 +03:00
|
|
|
async function initCore({ghostServer, config, bootLogger, frontend}) {
|
2021-02-19 14:51:01 +03:00
|
|
|
debug('Begin: initCore');
|
2021-06-28 12:50:41 +03:00
|
|
|
|
|
|
|
// URL Utils is a bit slow, put it here so the timing is visible separate from models
|
|
|
|
debug('Begin: Load urlUtils');
|
|
|
|
require('./shared/url-utils');
|
|
|
|
debug('End: Load urlUtils');
|
|
|
|
|
2021-02-23 14:49:59 +03:00
|
|
|
// Models are the heart of Ghost - this is a syncronous operation
|
|
|
|
debug('Begin: models');
|
|
|
|
const models = require('./server/models');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
models.init();
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('End: models');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-02-23 14:49:59 +03:00
|
|
|
// Settings are a core concept we use settings to store key-value pairs used in critical pathways as well as public data like the site title
|
|
|
|
debug('Begin: settings');
|
|
|
|
const settings = require('./server/services/settings');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
await settings.init();
|
2021-07-27 13:07:11 +03:00
|
|
|
await settings.syncEmailSettings(config.get('hostSettings:emailVerification:verified'));
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('End: settings');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-10-18 17:27:57 +03:00
|
|
|
// The URLService is a core part of Ghost, which depends on models.
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
debug('Begin: Url Service');
|
2021-10-18 17:27:57 +03:00
|
|
|
const urlService = require('./server/services/url');
|
2021-02-22 17:09:39 +03:00
|
|
|
// Note: there is no await here, we do not wait for the url service to finish
|
2021-11-24 12:02:59 +03:00
|
|
|
// We can return, but the site will remain in maintenance mode until this finishes
|
|
|
|
// This is managed on request: https://github.com/TryGhost/Ghost/blob/main/core/app.js#L10
|
2021-11-12 13:28:48 +03:00
|
|
|
urlService.init({
|
|
|
|
onFinished: () => {
|
|
|
|
bootLogger.log('URL Service Ready');
|
2021-11-17 19:00:27 +03:00
|
|
|
},
|
2021-11-22 09:51:54 +03:00
|
|
|
urlCache: !frontend // hacky parameter to make the cache initialization kick in as we can't initialize labs before the boot
|
2021-11-12 13:28:48 +03:00
|
|
|
});
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
debug('End: Url Service');
|
|
|
|
|
2021-12-02 11:00:31 +03:00
|
|
|
if (ghostServer) {
|
|
|
|
// Job Service allows parts of Ghost to run in the background
|
|
|
|
debug('Begin: Job Service');
|
|
|
|
const jobService = require('./server/services/jobs');
|
|
|
|
ghostServer.registerCleanupTask(async () => {
|
|
|
|
await jobService.shutdown();
|
|
|
|
});
|
|
|
|
debug('End: Job Service');
|
|
|
|
|
|
|
|
ghostServer.registerCleanupTask(async () => {
|
|
|
|
await urlService.shutdown();
|
|
|
|
});
|
|
|
|
}
|
2021-02-23 14:49:59 +03:00
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
debug('End: initCore');
|
|
|
|
}
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
/**
|
2021-10-04 19:12:18 +03:00
|
|
|
* These are services required by Ghost's frontend.
|
2022-03-24 12:16:19 +03:00
|
|
|
* @param {object} options
|
|
|
|
* @param {object} options.bootLogger
|
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
*/
|
2022-03-24 12:16:19 +03:00
|
|
|
async function initServicesForFrontend({bootLogger}) {
|
2021-10-04 19:12:18 +03:00
|
|
|
debug('Begin: initServicesForFrontend');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-10-04 18:50:07 +03:00
|
|
|
debug('Begin: Routing Settings');
|
2021-09-23 19:17:46 +03:00
|
|
|
const routeSettings = require('./server/services/route-settings');
|
|
|
|
await routeSettings.init();
|
2021-10-04 18:50:07 +03:00
|
|
|
debug('End: Routing Settings');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-11-25 11:52:01 +03:00
|
|
|
debug('Begin: Redirects');
|
|
|
|
const customRedirects = require('./server/services/redirects');
|
|
|
|
await customRedirects.init(),
|
|
|
|
debug('End: Redirects');
|
|
|
|
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('Begin: Themes');
|
2021-10-11 14:23:34 +03:00
|
|
|
// customThemSettingsService.api must be initialized before any theme activation occurs
|
2021-10-08 18:18:49 +03:00
|
|
|
const customThemeSettingsService = require('./server/services/custom-theme-settings');
|
|
|
|
customThemeSettingsService.init();
|
2022-03-24 12:16:19 +03:00
|
|
|
|
2021-10-11 14:23:34 +03:00
|
|
|
const themeService = require('./server/services/themes');
|
2022-03-24 12:16:19 +03:00
|
|
|
const themeServiceStart = Date.now();
|
2021-10-11 14:23:34 +03:00
|
|
|
await themeService.init();
|
2022-03-24 12:16:19 +03:00
|
|
|
bootLogger.metric('theme-service-init', themeServiceStart);
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('End: Themes');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2022-03-24 12:18:52 +03:00
|
|
|
debug('Begin: Offers');
|
|
|
|
const offers = require('./server/services/offers');
|
|
|
|
await offers.init();
|
|
|
|
debug('End: Offers');
|
|
|
|
|
2021-10-04 19:12:18 +03:00
|
|
|
debug('End: initServicesForFrontend');
|
2021-02-19 14:51:01 +03:00
|
|
|
}
|
|
|
|
|
2021-10-04 18:50:07 +03:00
|
|
|
/**
|
|
|
|
* Frontend is intended to be just Ghost's frontend
|
|
|
|
*/
|
|
|
|
async function initFrontend() {
|
|
|
|
debug('Begin: initFrontend');
|
|
|
|
|
|
|
|
const helperService = require('./frontend/services/helpers');
|
|
|
|
await helperService.init();
|
|
|
|
|
|
|
|
debug('End: initFrontend');
|
|
|
|
}
|
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
/**
|
|
|
|
* At the moment we load our express apps all in one go, they require themselves and are co-located
|
|
|
|
* What we want is to be able to optionally load various components and mount them
|
|
|
|
* So eventually this function should go away
|
2021-11-17 19:00:27 +03:00
|
|
|
* @param {Object} options
|
2021-11-22 09:51:54 +03:00
|
|
|
* @param {Boolean} options.backend
|
|
|
|
* @param {Boolean} options.frontend
|
2021-12-01 18:56:29 +03:00
|
|
|
* @param {Object} options.config
|
2021-02-19 14:51:01 +03:00
|
|
|
*/
|
2021-12-01 18:56:29 +03:00
|
|
|
async function initExpressApps({frontend, backend, config}) {
|
2021-02-19 14:51:01 +03:00
|
|
|
debug('Begin: initExpressApps');
|
2021-12-01 18:56:29 +03:00
|
|
|
|
|
|
|
const parentApp = require('./server/web/parent/app')();
|
|
|
|
const vhost = require('@tryghost/vhost-middleware');
|
|
|
|
|
|
|
|
// Mount the express apps on the parentApp
|
|
|
|
if (backend) {
|
|
|
|
// ADMIN + API
|
|
|
|
const backendApp = require('./server/web/parent/backend')();
|
|
|
|
parentApp.use(vhost(config.getBackendMountPath(), backendApp));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frontend) {
|
|
|
|
// SITE + MEMBERS
|
2022-04-13 13:09:22 +03:00
|
|
|
const urlService = require('./server/services/url');
|
|
|
|
const frontendApp = require('./server/web/parent/frontend')({urlService});
|
2021-12-01 18:56:29 +03:00
|
|
|
parentApp.use(vhost(config.getFrontendMountPath(), frontendApp));
|
|
|
|
}
|
|
|
|
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
debug('End: initExpressApps');
|
|
|
|
return parentApp;
|
2021-02-19 14:51:01 +03:00
|
|
|
}
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
/**
|
2021-10-04 19:12:18 +03:00
|
|
|
* Dynamic routing is generated from the routes.yaml file
|
2021-10-18 21:01:38 +03:00
|
|
|
* When Ghost's DB and core are loaded, we can access this file and call routing.routingManager.start
|
2021-06-28 12:04:59 +03:00
|
|
|
* However this _must_ happen after the express Apps are loaded, hence why this is here and not in initFrontend
|
|
|
|
* Routing is currently tightly coupled between the frontend and backend
|
2021-02-19 14:51:01 +03:00
|
|
|
*/
|
2021-06-28 12:04:59 +03:00
|
|
|
async function initDynamicRouting() {
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('Begin: Dynamic Routing');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
const routing = require('./frontend/services/routing');
|
2021-09-27 13:29:54 +03:00
|
|
|
const routeSettingsService = require('./server/services/route-settings');
|
2021-04-26 16:38:57 +03:00
|
|
|
const bridge = require('./bridge');
|
2021-11-22 13:51:23 +03:00
|
|
|
bridge.init();
|
2021-07-06 13:38:52 +03:00
|
|
|
|
2022-04-06 13:40:28 +03:00
|
|
|
// We pass the dynamic routes here, so that the frontend services are slightly less tightly-coupled
|
2021-09-27 15:15:06 +03:00
|
|
|
const routeSettings = await routeSettingsService.loadRouteSettings();
|
2021-07-06 13:38:52 +03:00
|
|
|
|
2022-04-06 13:40:28 +03:00
|
|
|
routing.routerManager.start(routeSettings);
|
2021-09-27 17:34:15 +03:00
|
|
|
const getRoutesHash = () => routeSettingsService.api.getCurrentHash();
|
2021-07-06 13:38:52 +03:00
|
|
|
|
|
|
|
const settings = require('./server/services/settings');
|
2021-02-23 14:49:59 +03:00
|
|
|
await settings.syncRoutesHash(getRoutesHash);
|
2021-07-06 13:38:52 +03:00
|
|
|
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('End: Dynamic Routing');
|
2021-06-28 12:04:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-20 16:27:11 +03:00
|
|
|
* Services are components that make up part of Ghost and need initializing on boot
|
2021-06-28 12:04:59 +03:00
|
|
|
* These services should all be part of core, frontend services should be loaded with the frontend
|
|
|
|
* We are working towards this being a service loader, with the ability to make certain services optional
|
|
|
|
*
|
|
|
|
* @param {object} options
|
|
|
|
* @param {object} options.config
|
|
|
|
*/
|
|
|
|
async function initServices({config}) {
|
|
|
|
debug('Begin: initServices');
|
|
|
|
|
|
|
|
const defaultApiVersion = config.get('api:versions:default');
|
|
|
|
debug(`Default API Version: ${defaultApiVersion}`);
|
2021-02-23 14:49:59 +03:00
|
|
|
|
|
|
|
debug('Begin: Services');
|
2021-10-04 14:18:22 +03:00
|
|
|
const stripe = require('./server/services/stripe');
|
2021-05-12 15:48:59 +03:00
|
|
|
const members = require('./server/services/members');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
const permissions = require('./server/services/permissions');
|
|
|
|
const xmlrpc = require('./server/services/xmlrpc');
|
|
|
|
const slack = require('./server/services/slack');
|
|
|
|
const {mega} = require('./server/services/mega');
|
|
|
|
const webhooks = require('./server/services/webhooks');
|
2021-02-23 14:49:59 +03:00
|
|
|
const appService = require('./frontend/services/apps');
|
2021-03-03 15:35:45 +03:00
|
|
|
const limits = require('./server/services/limits');
|
2022-04-22 05:29:55 +03:00
|
|
|
const apiVersionCompatibility = require('./server/services/api-version-compatibility');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
const scheduling = require('./server/adapters/scheduling');
|
2021-02-23 14:49:59 +03:00
|
|
|
|
|
|
|
const urlUtils = require('./shared/url-utils');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-05-11 17:11:09 +03:00
|
|
|
// NOTE: limits service has to be initialized first
|
|
|
|
// in case it limits initialization of any other service (e.g. webhooks)
|
|
|
|
await limits.init();
|
|
|
|
|
2021-10-06 16:21:19 +03:00
|
|
|
// NOTE: Members service depends on these
|
|
|
|
// so they are initialized before it.
|
2021-10-04 14:18:22 +03:00
|
|
|
await stripe.init();
|
|
|
|
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
await Promise.all([
|
2021-05-12 15:48:59 +03:00
|
|
|
members.init(),
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
permissions.init(),
|
|
|
|
xmlrpc.listen(),
|
|
|
|
slack.listen(),
|
|
|
|
mega.listen(),
|
|
|
|
webhooks.listen(),
|
|
|
|
appService.init(),
|
2022-04-22 05:29:55 +03:00
|
|
|
apiVersionCompatibility.init(),
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
scheduling.init({
|
2021-04-21 16:57:07 +03:00
|
|
|
apiUrl: urlUtils.urlFor('api', {version: defaultApiVersion, versionType: 'admin'}, true)
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
})
|
|
|
|
]);
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('End: Services');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-07-20 16:27:11 +03:00
|
|
|
// Initialize analytics events
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
if (config.get('segment:key')) {
|
2021-02-09 15:40:52 +03:00
|
|
|
require('./server/analytics-events').init();
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
}
|
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
debug('End: initServices');
|
|
|
|
}
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
/**
|
2021-02-22 20:30:25 +03:00
|
|
|
* Kick off recurring jobs and background services
|
2021-02-19 14:51:01 +03:00
|
|
|
* These are things that happen on boot, but we don't need to wait for them to finish
|
2021-10-04 19:12:18 +03:00
|
|
|
* Later, this might be a service hook
|
2021-06-28 12:04:59 +03:00
|
|
|
|
|
|
|
* @param {object} options
|
|
|
|
* @param {object} options.config
|
2021-02-19 14:51:01 +03:00
|
|
|
*/
|
2021-02-22 20:30:25 +03:00
|
|
|
async function initBackgroundServices({config}) {
|
|
|
|
debug('Begin: initBackgroundServices');
|
|
|
|
|
2021-07-06 19:10:15 +03:00
|
|
|
// Load all inactive themes
|
|
|
|
const themeService = require('./server/services/themes');
|
|
|
|
themeService.loadInactiveThemes();
|
|
|
|
|
2021-02-22 20:30:25 +03:00
|
|
|
// we don't want to kick off background services that will interfere with tests
|
2021-11-19 14:51:19 +03:00
|
|
|
if (process.env.NODE_ENV.startsWith('test')) {
|
2021-02-19 13:09:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-22 20:30:25 +03:00
|
|
|
// Load email analytics recurring jobs
|
2021-02-19 13:09:41 +03:00
|
|
|
if (config.get('backgroundJobs:emailAnalytics')) {
|
|
|
|
const emailAnalyticsJobs = require('./server/services/email-analytics/jobs');
|
|
|
|
await emailAnalyticsJobs.scheduleRecurringJobs();
|
|
|
|
}
|
|
|
|
|
2021-06-28 09:01:36 +03:00
|
|
|
const updateCheck = require('./server/update-check');
|
2021-06-23 14:01:43 +03:00
|
|
|
updateCheck.scheduleRecurringJobs();
|
2021-05-27 17:36:46 +03:00
|
|
|
|
2021-02-22 20:30:25 +03:00
|
|
|
debug('End: initBackgroundServices');
|
2021-02-19 13:09:41 +03:00
|
|
|
}
|
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
/**
|
|
|
|
* ----------------------------------
|
|
|
|
* Boot Ghost - The magic starts here
|
|
|
|
* ----------------------------------
|
|
|
|
*
|
|
|
|
* - This function is written with async/await so you can read, line by line, what happens on boot
|
|
|
|
* - All the functions above handle init/boot logic for a single component
|
2021-06-28 12:04:59 +03:00
|
|
|
|
|
|
|
* @returns {Promise<object>} ghostServer
|
2021-02-19 14:51:01 +03:00
|
|
|
*/
|
2021-12-02 11:00:31 +03:00
|
|
|
async function bootGhost({backend = true, frontend = true, server = true} = {}) {
|
2021-02-19 12:10:45 +03:00
|
|
|
// Metrics
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
const startTime = Date.now();
|
2021-02-19 14:51:01 +03:00
|
|
|
debug('Begin Boot');
|
2021-02-23 12:43:12 +03:00
|
|
|
|
|
|
|
// We need access to these variables in both the try and catch block
|
2021-03-18 14:58:24 +03:00
|
|
|
let bootLogger;
|
|
|
|
let config;
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
let ghostServer;
|
2021-02-23 12:43:12 +03:00
|
|
|
let logging;
|
2021-10-12 16:29:10 +03:00
|
|
|
let metrics;
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// These require their own try-catch block and error format, because we can't log an error if logging isn't working
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
try {
|
2021-03-18 14:58:24 +03:00
|
|
|
// Step 0 - Load config and logging - fundamental required components
|
2021-11-16 17:44:14 +03:00
|
|
|
// Version is required by logging, sentry & Migration config & so is fundamental to booting
|
|
|
|
// However, it involves reading package.json so its slow & it's here for visibility on that slowness
|
|
|
|
debug('Begin: Load version info');
|
|
|
|
require('@tryghost/version');
|
|
|
|
debug('End: Load version info');
|
|
|
|
|
|
|
|
// Loading config must be the first thing we do, because it is required for absolutely everything
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
debug('Begin: Load config');
|
2021-03-18 14:58:24 +03:00
|
|
|
config = require('./shared/config');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
debug('End: Load config');
|
|
|
|
|
2021-11-16 17:44:14 +03:00
|
|
|
// Logging is also used absolutely everywhere
|
2021-02-16 14:54:19 +03:00
|
|
|
debug('Begin: Load logging');
|
2021-06-15 17:36:27 +03:00
|
|
|
logging = require('@tryghost/logging');
|
2021-10-12 16:29:10 +03:00
|
|
|
metrics = require('@tryghost/metrics');
|
|
|
|
bootLogger = new BootLogger(logging, metrics, startTime);
|
2021-02-16 14:54:19 +03:00
|
|
|
debug('End: Load logging');
|
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// At this point logging is required, so we can handle errors better
|
2022-02-18 12:28:28 +03:00
|
|
|
|
|
|
|
// Add a process handler to capture and log unhandled rejections
|
|
|
|
debug('Begin: Add unhandled rejection handler');
|
|
|
|
process.on('unhandledRejection', (error) => {
|
|
|
|
logging.error('Unhandled rejection:', error);
|
|
|
|
});
|
|
|
|
debug('End: Add unhandled rejection handler');
|
2021-03-18 14:58:24 +03:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error); // eslint-disable-line no-console
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Step 1 - require more fundamental components
|
2021-07-20 16:27:11 +03:00
|
|
|
// Sentry must be initialized early, but requires config
|
2021-02-19 12:10:45 +03:00
|
|
|
debug('Begin: Load sentry');
|
|
|
|
require('./shared/sentry');
|
|
|
|
debug('End: Load sentry');
|
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// Step 2 - Start server with minimal app in global maintenance mode
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
debug('Begin: load server + minimal app');
|
2021-12-03 19:26:51 +03:00
|
|
|
const rootApp = require('./app')();
|
2021-11-17 19:00:27 +03:00
|
|
|
|
2021-12-02 11:00:31 +03:00
|
|
|
if (server) {
|
|
|
|
const GhostServer = require('./server/ghost-server');
|
2022-04-20 14:47:25 +03:00
|
|
|
ghostServer = new GhostServer({url: config.getSiteUrl(), env: config.get('env'), serverConfig: config.get('server')});
|
2021-12-02 11:00:31 +03:00
|
|
|
await ghostServer.start(rootApp);
|
|
|
|
bootLogger.log('server started');
|
|
|
|
debug('End: load server + minimal app');
|
|
|
|
}
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// Step 3 - Get the DB ready
|
2021-02-16 14:54:19 +03:00
|
|
|
debug('Begin: Get DB ready');
|
2021-12-14 14:22:39 +03:00
|
|
|
await initDatabase({config});
|
2021-02-16 14:54:19 +03:00
|
|
|
bootLogger.log('database ready');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
debug('End: Get DB ready');
|
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// Step 4 - Load Ghost with all its services
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('Begin: Load Ghost Services & Apps');
|
2021-11-22 09:51:54 +03:00
|
|
|
await initCore({ghostServer, config, bootLogger, frontend});
|
2022-03-24 12:16:19 +03:00
|
|
|
await initServicesForFrontend({bootLogger});
|
2021-11-17 19:00:27 +03:00
|
|
|
|
2021-11-22 09:51:54 +03:00
|
|
|
if (frontend) {
|
2021-11-17 19:00:27 +03:00
|
|
|
await initFrontend();
|
|
|
|
}
|
2021-12-01 18:56:29 +03:00
|
|
|
const ghostApp = await initExpressApps({frontend, backend, config});
|
2021-11-17 19:00:27 +03:00
|
|
|
|
2021-11-22 09:51:54 +03:00
|
|
|
if (frontend) {
|
2021-11-17 19:00:27 +03:00
|
|
|
await initDynamicRouting();
|
|
|
|
}
|
|
|
|
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
await initServices({config});
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('End: Load Ghost Services & Apps');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// Step 5 - Mount the full Ghost app onto the minimal root app & disable maintenance mode
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('Begin: mountGhost');
|
|
|
|
rootApp.disable('maintenance');
|
2021-06-28 12:50:41 +03:00
|
|
|
rootApp.use(config.getSubdir(), ghostApp);
|
2021-02-23 14:49:59 +03:00
|
|
|
debug('End: mountGhost');
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// Step 6 - We are technically done here - let everyone know!
|
2021-02-16 14:54:19 +03:00
|
|
|
bootLogger.log('booted');
|
2021-10-12 16:29:10 +03:00
|
|
|
bootLogger.metric('boot-time');
|
2021-02-19 23:32:37 +03:00
|
|
|
notifyServerReady();
|
2021-02-18 23:06:16 +03:00
|
|
|
|
2021-03-18 14:58:24 +03:00
|
|
|
// Step 7 - Init our background services, we don't wait for this to finish
|
2021-02-22 20:30:25 +03:00
|
|
|
initBackgroundServices({config});
|
2021-02-19 14:51:01 +03:00
|
|
|
|
2021-02-23 14:49:59 +03:00
|
|
|
// We return the server purely for testing purposes
|
2021-12-02 11:00:31 +03:00
|
|
|
if (server) {
|
|
|
|
debug('End Boot: Returning Ghost Server');
|
|
|
|
return ghostServer;
|
|
|
|
} else {
|
|
|
|
debug('End boot: Returning Root App');
|
|
|
|
return rootApp;
|
|
|
|
}
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
} catch (error) {
|
|
|
|
const errors = require('@tryghost/errors');
|
|
|
|
|
2021-02-23 12:43:12 +03:00
|
|
|
// Ensure the error we have is an ignition error
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
let serverStartError = error;
|
2021-12-01 13:22:01 +03:00
|
|
|
if (!errors.utils.isGhostError(serverStartError)) {
|
|
|
|
serverStartError = new errors.InternalServerError({message: serverStartError.message, err: serverStartError});
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
logging.error(serverStartError);
|
|
|
|
|
2021-02-19 14:51:01 +03:00
|
|
|
// If ghost was started and something else went wrong, we shut it down
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
if (ghostServer) {
|
2021-02-19 23:32:37 +03:00
|
|
|
notifyServerReady(serverStartError);
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
ghostServer.shutdown(2);
|
|
|
|
} else {
|
2021-02-19 14:51:01 +03:00
|
|
|
// Ghost server failed to start, set a timeout to give logging a chance to flush
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
setTimeout(() => {
|
|
|
|
process.exit(2);
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
}
|
2021-02-19 14:51:01 +03:00
|
|
|
}
|
Added new, simpler, linear boot process
Background:
- Ghosts existing boot process is split across multiple files, has affordances for outdated ways of running Ghost and is generally non-linear making it nigh-impossible to follow
- The web of dependencies that are loaded on boot are also impossible to unpick, which makes it really hard to decouple Ghost
- With 4.0 we want to introduce a new, linear, simpler, clearer way to boot up Ghost to unlock decoupling Ghost into much smaller pieces
This commit:
- adds a new ghost.js file which switches between boot mode with `node index` or `node index old` so that if we find bugs we can work around them this week
- Note: the old boot process will go away very soon, but ghost.js will remain as the interface between the command to start Ghost and the application code
- reworks the database migration process into a standalone utility, so that the DB is handled as one simple step of the boot process, decoupled from everything else
- is missing tests for this new db utility
- leaves a lot of work to do around loading core code, services, express apps in a sensible order, as work to fix this would start to break the old boot process
- doesn't use the new maintenance app because we aren't restarting the server here, instead we have the concept of a "core app" that starts in maintenance mode - need to think about how apps will be decoupled in the near future
2021-02-02 17:47:16 +03:00
|
|
|
|
|
|
|
module.exports = bootGhost;
|