Files
wiki/server/core/kernel.js
T

120 lines
3.0 KiB
JavaScript
Raw Normal View History

const _ = require('lodash')
2020-02-02 21:55:29 -05:00
const EventEmitter = require('eventemitter2').EventEmitter2
2018-03-05 15:49:36 -05:00
/* global WIKI */
2017-10-07 22:44:35 -04:00
module.exports = {
2018-05-28 14:46:55 -04:00
async init() {
WIKI.logger.info('=======================================')
WIKI.logger.info(`= Wiki.js ${_.padEnd(WIKI.version + ' ', 29, '=')}`)
2018-05-28 14:46:55 -04:00
WIKI.logger.info('=======================================')
2019-05-27 00:28:12 -04:00
WIKI.logger.info('Initializing...')
2017-10-07 22:44:35 -04:00
WIKI.models = require('./db').init()
2017-10-07 22:44:35 -04:00
2019-02-22 17:05:18 -05:00
try {
await WIKI.models.onReady
await WIKI.configSvc.loadFromDb()
2019-02-23 18:22:25 -05:00
await WIKI.configSvc.applyFlags()
2019-02-22 17:05:18 -05:00
} catch (err) {
WIKI.logger.error('Database Initialization Error: ' + err.message)
if (WIKI.IS_DEBUG) {
WIKI.logger.error(err)
2019-02-22 17:05:18 -05:00
}
process.exit(1)
}
2018-05-28 14:46:55 -04:00
this.bootMaster()
2017-10-07 22:44:35 -04:00
},
/**
* Pre-Master Boot Sequence
*/
2018-05-28 14:46:55 -04:00
async preBootMaster() {
try {
await this.initTelemetry()
WIKI.sideloader = await require('./sideloader').init()
WIKI.cache = require('./cache').init()
WIKI.scheduler = require('./scheduler').init()
2020-01-11 22:33:19 -05:00
WIKI.servers = require('./servers')
2020-04-19 20:26:26 -04:00
WIKI.events = {
inbound: new EventEmitter(),
outbound: new EventEmitter()
}
2020-05-18 00:45:51 -04:00
WIKI.extensions = require('./extensions')
2020-05-24 18:02:05 -04:00
WIKI.asar = require('./asar')
2018-05-28 14:46:55 -04:00
} catch (err) {
WIKI.logger.error(err)
process.exit(1)
}
2017-10-07 22:44:35 -04:00
},
/**
* Boot Master Process
*/
2018-05-28 14:46:55 -04:00
async bootMaster() {
try {
await this.preBootMaster()
await require('../master')()
this.postBootMaster()
2018-05-28 14:46:55 -04:00
} catch (err) {
2018-03-05 15:49:36 -05:00
WIKI.logger.error(err)
2017-10-07 22:44:35 -04:00
process.exit(1)
2018-05-28 14:46:55 -04:00
}
2017-10-07 22:44:35 -04:00
},
/**
* Post-Master Boot Sequence
*/
2017-12-24 00:34:47 -05:00
async postBootMaster() {
await WIKI.models.analytics.refreshProvidersFromDisk()
2018-08-04 17:27:55 -04:00
await WIKI.models.authentication.refreshStrategiesFromDisk()
2020-04-06 22:21:42 -04:00
await WIKI.models.commentProviders.refreshProvidersFromDisk()
2018-08-20 01:02:57 -04:00
await WIKI.models.editors.refreshEditorsFromDisk()
2018-08-26 22:38:08 -04:00
await WIKI.models.renderers.refreshRenderersFromDisk()
await WIKI.models.storage.refreshTargetsFromDisk()
2020-05-18 00:45:51 -04:00
await WIKI.extensions.init()
await WIKI.auth.activateStrategies()
2020-05-16 22:46:05 -04:00
await WIKI.models.commentProviders.initProvider()
2019-02-03 17:08:06 -05:00
await WIKI.models.storage.initTargets()
WIKI.scheduler.start()
2020-04-19 20:26:26 -04:00
await WIKI.models.subscribeToNotifications()
2019-02-02 01:17:09 -05:00
},
/**
* Init Telemetry
*/
async initTelemetry() {
require('./telemetry').init()
process.on('unhandledRejection', (err) => {
WIKI.logger.warn(err)
WIKI.telemetry.sendError(err)
})
process.on('uncaughtException', (err) => {
WIKI.logger.warn(err)
WIKI.telemetry.sendError(err)
})
2020-02-02 21:55:29 -05:00
},
/**
* Graceful shutdown
*/
async shutdown () {
2021-04-12 23:45:33 +08:00
if (WIKI.servers) {
await WIKI.servers.stopServers()
2020-02-02 21:55:29 -05:00
}
if (WIKI.scheduler) {
2021-04-12 23:45:33 +08:00
await WIKI.scheduler.stop()
}
if (WIKI.models) {
await WIKI.models.unsubscribeToNotifications()
if (WIKI.models.knex) {
await WIKI.models.knex.destroy()
}
2020-02-02 21:55:29 -05:00
}
2020-05-24 18:02:05 -04:00
if (WIKI.asar) {
await WIKI.asar.unload()
}
2021-04-12 23:45:33 +08:00
process.exit(0)
2017-10-07 22:44:35 -04:00
}
}