wiki/server/core/kernel.js

93 lines
2.3 KiB
JavaScript
Raw Normal View History

const _ = require('lodash')
const EventEmitter = require('events')
/* global WIKI */
2017-10-07 21:44:35 -05:00
module.exports = {
2018-05-28 13:46:55 -05:00
async init() {
WIKI.logger.info('=======================================')
WIKI.logger.info(`= Wiki.js ${_.padEnd(WIKI.version + ' ', 29, '=')}`)
2018-05-28 13:46:55 -05:00
WIKI.logger.info('=======================================')
WIKI.logger.info('Initializing...')
2017-10-07 21:44:35 -05:00
WIKI.models = require('./db').init()
2017-10-07 21:44:35 -05:00
2019-02-22 16:05:18 -06:00
try {
await WIKI.models.onReady
await WIKI.configSvc.loadFromDb()
2019-02-23 17:22:25 -06:00
await WIKI.configSvc.applyFlags()
2019-02-22 16:05:18 -06:00
} catch (err) {
WIKI.logger.error('Database Initialization Error: ' + err.message)
if (WIKI.IS_DEBUG) {
console.error(err)
}
process.exit(1)
}
2018-05-28 13:46:55 -05:00
this.bootMaster()
2017-10-07 21:44:35 -05:00
},
/**
* Pre-Master Boot Sequence
*/
2018-05-28 13:46:55 -05:00
async preBootMaster() {
try {
await this.initTelemetry()
WIKI.cache = require('./cache').init()
WIKI.scheduler = require('./scheduler').init()
WIKI.events = new EventEmitter()
2018-05-28 13:46:55 -05:00
} catch (err) {
WIKI.logger.error(err)
process.exit(1)
}
2017-10-07 21:44:35 -05:00
},
/**
* Boot Master Process
*/
2018-05-28 13:46:55 -05:00
async bootMaster() {
try {
if (WIKI.config.setup) {
WIKI.logger.info('Starting setup wizard...')
2017-12-23 23:34:47 -06:00
require('../setup')()
2018-05-28 13:46:55 -05:00
} else {
await this.preBootMaster()
2018-05-28 13:46:55 -05:00
await require('../master')()
this.postBootMaster()
2017-10-07 21:44:35 -05:00
}
2018-05-28 13:46:55 -05:00
} catch (err) {
WIKI.logger.error(err)
2017-10-07 21:44:35 -05:00
process.exit(1)
2018-05-28 13:46:55 -05:00
}
2017-10-07 21:44:35 -05:00
},
/**
* Post-Master Boot Sequence
*/
2017-12-23 23:34:47 -06:00
async postBootMaster() {
2018-08-04 16:27:55 -05:00
await WIKI.models.authentication.refreshStrategiesFromDisk()
2018-08-20 00:02:57 -05:00
await WIKI.models.editors.refreshEditorsFromDisk()
2018-09-01 14:15:44 -05:00
await WIKI.models.loggers.refreshLoggersFromDisk()
await WIKI.models.renderers.refreshRenderersFromDisk()
2018-09-01 14:15:44 -05:00
await WIKI.models.searchEngines.refreshSearchEnginesFromDisk()
await WIKI.models.storage.refreshTargetsFromDisk()
await WIKI.auth.activateStrategies()
2019-03-08 23:51:02 -06:00
await WIKI.models.searchEngines.initEngine()
2019-02-03 16:08:06 -06:00
await WIKI.models.storage.initTargets()
WIKI.scheduler.start()
2019-02-02 00:17:09 -06: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)
})
2017-10-07 21:44:35 -05:00
}
}