feat: Kernel module

This commit is contained in:
NGPixel
2017-10-07 22:44:35 -04:00
parent 2be7f71be8
commit c26fae2ede
13 changed files with 264 additions and 560 deletions

78
wiki.js
View File

@@ -1,13 +1,72 @@
#!/usr/bin/env node
'use strict'
// ===========================================
// Wiki.js
// 1.0.1
// 2.0
// Licensed under AGPLv3
// ===========================================
const init = require('./server/init')
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
const pm2 = Promise.promisifyAll(require('pm2'))
const ora = require('ora')
const path = require('path')
const ROOTPATH = process.cwd()
const init = {
/**
* Start in background mode
*/
start () {
let spinner = ora('Initializing...').start()
return fs.emptyDirAsync(path.join(ROOTPATH, './logs')).then(() => {
return pm2.connectAsync().then(() => {
return pm2.startAsync({
name: 'wiki',
script: 'server',
cwd: ROOTPATH,
output: path.join(ROOTPATH, './logs/wiki-output.log'),
error: path.join(ROOTPATH, './logs/wiki-error.log'),
minUptime: 5000,
maxRestarts: 5
}).then(() => {
spinner.succeed('Wiki.js has started successfully.')
}).finally(() => {
pm2.disconnect()
})
})
}).catch(err => {
spinner.fail(err)
process.exit(1)
})
},
/**
* Stop Wiki.js process(es)
*/
stop () {
let spinner = ora('Shutting down Wiki.js...').start()
return pm2.connectAsync().then(() => {
return pm2.stopAsync('wiki').then(() => {
spinner.succeed('Wiki.js has stopped successfully.')
}).finally(() => {
pm2.disconnect()
})
}).catch(err => {
spinner.fail(err)
process.exit(1)
})
},
/**
* Restart Wiki.js process(es)
*/
restart: function () {
let self = this
return self.stop().delay(1000).then(() => {
self.startDetect()
})
}
}
require('yargs') // eslint-disable-line no-unused-expressions
.usage('Usage: node $0 <cmd> [args]')
@@ -16,7 +75,7 @@ require('yargs') // eslint-disable-line no-unused-expressions
alias: ['boot', 'init'],
desc: 'Start Wiki.js process',
handler: argv => {
init.startDetect()
init.start()
}
})
.command({
@@ -35,18 +94,9 @@ require('yargs') // eslint-disable-line no-unused-expressions
init.restart()
}
})
.command({
command: 'configure [port]',
alias: ['config', 'conf', 'cfg', 'setup'],
desc: 'Configure Wiki.js using the web-based setup wizard',
builder: (yargs) => yargs.default('port', 3000),
handler: argv => {
init.configure(argv.port)
}
})
.recommendCommands()
.demandCommand(1, 'You must provide one of the accepted commands above.')
.help()
.version()
.epilogue('Read the docs at https://wiki.requarks.io')
.epilogue('Read the docs at https://docs.requarks.io/wiki')
.argv