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.

56 lines
1.3 KiB

  1. // ===========================================
  2. // Wiki.js
  3. // Licensed under AGPLv3
  4. // ===========================================
  5. const path = require('path')
  6. const { nanoid } = require('nanoid')
  7. const { DateTime } = require('luxon')
  8. const { gte } = require('semver')
  9. // ----------------------------------------
  10. // Init WIKI instance
  11. // ----------------------------------------
  12. let WIKI = {
  13. IS_DEBUG: process.env.NODE_ENV === 'development',
  14. IS_MASTER: true,
  15. ROOTPATH: process.cwd(),
  16. INSTANCE_ID: nanoid(10),
  17. SERVERPATH: path.join(process.cwd(), 'server'),
  18. Error: require('./helpers/error'),
  19. configSvc: require('./core/config'),
  20. kernel: require('./core/kernel'),
  21. startedAt: DateTime.utc()
  22. }
  23. global.WIKI = WIKI
  24. WIKI.configSvc.init()
  25. // ----------------------------------------
  26. // Init Logger
  27. // ----------------------------------------
  28. WIKI.logger = require('./core/logger').init('MASTER')
  29. // ----------------------------------------
  30. // Start Kernel
  31. // ----------------------------------------
  32. WIKI.kernel.init()
  33. // ----------------------------------------
  34. // Register exit handler
  35. // ----------------------------------------
  36. process.on('SIGTERM', () => {
  37. WIKI.kernel.shutdown()
  38. })
  39. process.on('SIGINT', () => {
  40. WIKI.kernel.shutdown()
  41. })
  42. process.on('message', (msg) => {
  43. if (msg === 'shutdown') {
  44. WIKI.kernel.shutdown()
  45. }
  46. })