2017-02-09 01:52:37 +00:00
|
|
|
'use strict'
|
|
|
|
|
2016-08-17 00:56:55 +00:00
|
|
|
// ===========================================
|
2016-12-09 03:44:31 +00:00
|
|
|
// Wiki.js
|
2016-08-17 00:56:55 +00:00
|
|
|
// Licensed under AGPLv3
|
|
|
|
// ===========================================
|
|
|
|
|
2017-04-28 21:58:38 +00:00
|
|
|
const path = require('path')
|
2017-07-29 21:33:08 +00:00
|
|
|
const cluster = require('cluster')
|
|
|
|
|
2017-07-23 03:56:46 +00:00
|
|
|
let wiki = {
|
|
|
|
IS_DEBUG: process.env.NODE_ENV === 'development',
|
2017-07-29 21:33:08 +00:00
|
|
|
IS_MASTER: cluster.isMaster,
|
2017-07-23 03:56:46 +00:00
|
|
|
ROOTPATH: process.cwd(),
|
2017-07-29 21:33:08 +00:00
|
|
|
SERVERPATH: path.join(process.cwd(), 'server'),
|
|
|
|
configSvc: require('./modules/config')
|
2017-07-23 03:56:46 +00:00
|
|
|
}
|
|
|
|
global.wiki = wiki
|
2016-08-20 21:20:53 +00:00
|
|
|
|
2017-02-09 01:52:37 +00:00
|
|
|
process.env.VIPS_WARNING = false
|
|
|
|
|
2017-07-23 03:56:46 +00:00
|
|
|
// if (wiki.IS_DEBUG) {
|
2017-05-19 00:23:24 +00:00
|
|
|
// require('@glimpse/glimpse').init()
|
|
|
|
// }
|
2017-05-14 17:56:33 +00:00
|
|
|
|
2017-07-29 21:33:08 +00:00
|
|
|
wiki.configSvc.init()
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Init Logger
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
wiki.logger = require('./modules/logger').init()
|
2017-03-29 00:19:01 +00:00
|
|
|
|
2016-08-17 00:56:55 +00:00
|
|
|
// ----------------------------------------
|
2017-07-29 21:33:08 +00:00
|
|
|
// Init DB
|
2016-08-17 00:56:55 +00:00
|
|
|
// ----------------------------------------
|
|
|
|
|
2017-07-29 21:33:08 +00:00
|
|
|
wiki.db = require('./modules/db').init()
|
2016-08-17 00:56:55 +00:00
|
|
|
|
2016-09-25 04:08:49 +00:00
|
|
|
// ----------------------------------------
|
2017-07-29 04:11:22 +00:00
|
|
|
// Start Cluster
|
2016-09-25 04:08:49 +00:00
|
|
|
// ----------------------------------------
|
2016-08-22 03:18:31 +00:00
|
|
|
|
2017-07-29 04:11:22 +00:00
|
|
|
const numCPUs = require('os').cpus().length
|
2017-07-29 21:33:08 +00:00
|
|
|
let numWorkers = (wiki.config.workers > 0) ? wiki.config.workers : numCPUs
|
|
|
|
if (numWorkers > numCPUs) {
|
|
|
|
numWorkers = numCPUs
|
|
|
|
}
|
2016-08-20 21:20:53 +00:00
|
|
|
|
2017-07-29 04:11:22 +00:00
|
|
|
if (cluster.isMaster) {
|
2017-08-03 03:47:11 +00:00
|
|
|
wiki.logger.info('--------------------------')
|
2017-07-29 04:11:22 +00:00
|
|
|
wiki.logger.info('Wiki.js is initializing...')
|
2017-08-03 03:47:11 +00:00
|
|
|
wiki.logger.info('--------------------------')
|
2016-08-17 03:56:08 +00:00
|
|
|
|
2017-08-03 03:47:11 +00:00
|
|
|
require('./master').then(() => {
|
|
|
|
// -> Create background workers
|
|
|
|
for (let i = 0; i < numWorkers; i++) {
|
|
|
|
cluster.fork()
|
|
|
|
}
|
2016-09-01 02:45:28 +00:00
|
|
|
|
2017-08-03 03:47:11 +00:00
|
|
|
// -> Queue post-init tasks
|
|
|
|
|
|
|
|
wiki.queue.uplClearTemp.add({}, {
|
|
|
|
repeat: { cron: '*/15 * * * *' }
|
|
|
|
})
|
|
|
|
})
|
2016-09-05 23:23:49 +00:00
|
|
|
|
2017-07-29 04:11:22 +00:00
|
|
|
cluster.on('exit', (worker, code, signal) => {
|
2017-08-03 03:47:11 +00:00
|
|
|
wiki.logger.info(`Background Worker #${worker.id} was terminated.`)
|
2017-05-19 00:23:24 +00:00
|
|
|
})
|
2017-07-29 04:11:22 +00:00
|
|
|
} else {
|
2017-08-03 03:47:11 +00:00
|
|
|
wiki.logger.info(`Background Worker #${cluster.worker.id} is initializing...`)
|
2017-07-29 21:33:08 +00:00
|
|
|
require('./worker')
|
2017-07-29 04:11:22 +00:00
|
|
|
}
|