index.js 1.59 KB
Newer Older
NGPixel's avatar
NGPixel committed
1
// ===========================================
2
// Wiki.js
NGPixel's avatar
NGPixel committed
3 4 5
// Licensed under AGPLv3
// ===========================================

6
const path = require('path')
7
const { nanoid } = require('nanoid')
8
const { DateTime } = require('luxon')
9 10 11 12 13
const { gte } = require('semver')

// ----------------------------------------
// Check Node.js version
// ----------------------------------------
14
if (gte(process.version, '21.0.0')) {
15 16 17 18 19 20 21
  console.error('You\'re using an unsupported Node.js version. Please read the requirements.')
  process.exit(1)
}

// ----------------------------------------
// Init WIKI instance
// ----------------------------------------
22

23
let WIKI = {
24
  IS_DEBUG: process.env.NODE_ENV === 'development',
25
  IS_MASTER: true,
26
  ROOTPATH: process.cwd(),
27
  INSTANCE_ID: nanoid(10),
28
  SERVERPATH: path.join(process.cwd(), 'server'),
29
  Error: require('./helpers/error'),
30
  configSvc: require('./core/config'),
31 32
  kernel: require('./core/kernel'),
  startedAt: DateTime.utc()
33
}
34
global.WIKI = WIKI
35

36
WIKI.configSvc.init()
37 38 39 40 41

// ----------------------------------------
// Init Logger
// ----------------------------------------

42
WIKI.logger = require('./core/logger').init('MASTER')
43

44
// ----------------------------------------
NGPixel's avatar
NGPixel committed
45
// Start Kernel
46
// ----------------------------------------
47

48
WIKI.kernel.init()
LK HO's avatar
LK HO committed
49 50 51 52 53

// ----------------------------------------
// Register exit handler
// ----------------------------------------

54 55 56
process.on('SIGTERM', () => {
  WIKI.kernel.shutdown()
})
LK HO's avatar
LK HO committed
57 58 59 60 61 62 63 64
process.on('SIGINT', () => {
  WIKI.kernel.shutdown()
})
process.on('message', (msg) => {
  if (msg === 'shutdown') {
    WIKI.kernel.shutdown()
  }
})