You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

6 years ago
6 years ago
  1. const _ = require('lodash')
  2. const EventEmitter = require('events')
  3. /* global WIKI */
  4. module.exports = {
  5. async init() {
  6. WIKI.logger.info('=======================================')
  7. WIKI.logger.info(`= Wiki.js ${_.padEnd(WIKI.version + ' ', 29, '=')}`)
  8. WIKI.logger.info('=======================================')
  9. WIKI.models = require('./db').init()
  10. WIKI.redis = require('./redis').init()
  11. WIKI.queue = require('./queue').init()
  12. await this.preBootMaster()
  13. this.bootMaster()
  14. },
  15. /**
  16. * Pre-Master Boot Sequence
  17. */
  18. async preBootMaster() {
  19. try {
  20. await WIKI.models.onReady
  21. await WIKI.configSvc.loadFromDb()
  22. await WIKI.queue.clean()
  23. WIKI.events = new EventEmitter()
  24. WIKI.redisSub = require('./redis').subscribe()
  25. } catch (err) {
  26. WIKI.logger.error(err)
  27. process.exit(1)
  28. }
  29. },
  30. /**
  31. * Boot Master Process
  32. */
  33. async bootMaster() {
  34. try {
  35. if (WIKI.config.setup) {
  36. WIKI.logger.info('Starting setup wizard...')
  37. require('../setup')()
  38. } else {
  39. await this.initTelemetry()
  40. await require('../master')()
  41. this.postBootMaster()
  42. }
  43. } catch (err) {
  44. WIKI.logger.error(err)
  45. process.exit(1)
  46. }
  47. },
  48. /**
  49. * Post-Master Boot Sequence
  50. */
  51. async postBootMaster() {
  52. await WIKI.models.authentication.refreshStrategiesFromDisk()
  53. await WIKI.models.editors.refreshEditorsFromDisk()
  54. await WIKI.models.loggers.refreshLoggersFromDisk()
  55. await WIKI.models.renderers.refreshRenderersFromDisk()
  56. await WIKI.models.searchEngines.refreshSearchEnginesFromDisk()
  57. await WIKI.models.storage.refreshTargetsFromDisk()
  58. await WIKI.auth.activateStrategies()
  59. await WIKI.models.storage.initTargets()
  60. await WIKI.queue.start()
  61. },
  62. /**
  63. * Init Telemetry
  64. */
  65. async initTelemetry() {
  66. require('./telemetry').init()
  67. process.on('unhandledRejection', (err) => {
  68. WIKI.logger.warn(err)
  69. WIKI.telemetry.sendError(err)
  70. })
  71. process.on('uncaughtException', (err) => {
  72. WIKI.logger.warn(err)
  73. WIKI.telemetry.sendError(err)
  74. })
  75. }
  76. }