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.

65 lines
1.7 KiB

  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 require('../master')()
  40. this.postBootMaster()
  41. }
  42. } catch (err) {
  43. WIKI.logger.error(err)
  44. process.exit(1)
  45. }
  46. },
  47. /**
  48. * Post-Master Boot Sequence
  49. */
  50. async postBootMaster() {
  51. await WIKI.models.authentication.refreshStrategiesFromDisk()
  52. await WIKI.models.editors.refreshEditorsFromDisk()
  53. await WIKI.models.loggers.refreshLoggersFromDisk()
  54. await WIKI.models.renderers.refreshRenderersFromDisk()
  55. await WIKI.models.searchEngines.refreshSearchEnginesFromDisk()
  56. await WIKI.models.storage.refreshTargetsFromDisk()
  57. await WIKI.auth.activateStrategies()
  58. await WIKI.queue.start()
  59. }
  60. }