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.

74 lines
1.8 KiB

  1. 'use strict'
  2. // ===========================================
  3. // Wiki.js
  4. // Licensed under AGPLv3
  5. // ===========================================
  6. const path = require('path')
  7. const cluster = require('cluster')
  8. let wiki = {
  9. IS_DEBUG: process.env.NODE_ENV === 'development',
  10. IS_MASTER: cluster.isMaster,
  11. ROOTPATH: process.cwd(),
  12. SERVERPATH: path.join(process.cwd(), 'server'),
  13. configSvc: require('./modules/config')
  14. }
  15. global.wiki = wiki
  16. process.env.VIPS_WARNING = false
  17. // if (wiki.IS_DEBUG) {
  18. // require('@glimpse/glimpse').init()
  19. // }
  20. wiki.configSvc.init()
  21. // ----------------------------------------
  22. // Init Logger
  23. // ----------------------------------------
  24. wiki.logger = require('./modules/logger').init()
  25. // ----------------------------------------
  26. // Init DB
  27. // ----------------------------------------
  28. wiki.db = require('./modules/db').init()
  29. // ----------------------------------------
  30. // Start Cluster
  31. // ----------------------------------------
  32. const numCPUs = require('os').cpus().length
  33. let numWorkers = (wiki.config.workers > 0) ? wiki.config.workers : numCPUs
  34. if (numWorkers > numCPUs) {
  35. numWorkers = numCPUs
  36. }
  37. if (cluster.isMaster) {
  38. wiki.logger.info('=======================================')
  39. wiki.logger.info('= Wiki.js =============================')
  40. wiki.logger.info('=======================================')
  41. require('./master').then(() => {
  42. // -> Create background workers
  43. for (let i = 0; i < numWorkers; i++) {
  44. cluster.fork()
  45. }
  46. // -> Queue post-init tasks
  47. wiki.queue.uplClearTemp.add({}, {
  48. repeat: { cron: '*/15 * * * *' }
  49. })
  50. })
  51. cluster.on('exit', (worker, code, signal) => {
  52. wiki.logger.info(`Background Worker #${worker.id} was terminated.`)
  53. })
  54. } else {
  55. wiki.logger.info(`Background Worker #${cluster.worker.id} is initializing...`)
  56. require('./worker')
  57. }