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.

75 lines
1.9 KiB

  1. #!/usr/bin/env node
  2. 'use strict'
  3. // ===========================================
  4. // Wiki.js
  5. // 1.0.0
  6. // Licensed under AGPLv3
  7. // ===========================================
  8. const Promise = require('bluebird')
  9. const fs = Promise.promisifyAll(require('fs-extra'))
  10. const ora = require('ora')
  11. const pm2 = Promise.promisifyAll(require('pm2'))
  12. const cmdr = require('commander')
  13. const path = require('path')
  14. const packageObj = fs.readJsonSync('package.json')
  15. cmdr.version(packageObj.version)
  16. cmdr.command('start')
  17. .description('Start Wiki.js process')
  18. .action(() => {
  19. let spinner = ora('Initializing...').start()
  20. fs.emptyDirAsync(path.join(__dirname, './logs')).then(() => {
  21. return pm2.connectAsync().then(() => {
  22. return pm2.startAsync({
  23. name: 'wiki',
  24. script: 'server.js',
  25. cwd: __dirname,
  26. output: path.join(__dirname, './logs/wiki-output.log'),
  27. error: path.join(__dirname, './logs/wiki-error.log'),
  28. minUptime: 5000,
  29. maxRestarts: 5
  30. }).then(() => {
  31. spinner.succeed('Wiki.js has started successfully.')
  32. }).finally(() => {
  33. pm2.disconnect()
  34. })
  35. })
  36. }).catch(err => {
  37. spinner.fail(err)
  38. process.exit(1)
  39. })
  40. })
  41. cmdr.command('stop')
  42. .description('Stop Wiki.js process')
  43. .action(() => {
  44. let spinner = ora('Shutting down Wiki.js...').start()
  45. pm2.connectAsync().then(() => {
  46. return pm2.stopAsync('wiki').then(() => {
  47. spinner.succeed('Wiki.js has stopped successfully.')
  48. }).finally(() => {
  49. pm2.disconnect()
  50. })
  51. }).catch(err => {
  52. spinner.fail(err)
  53. process.exit(1)
  54. })
  55. })
  56. cmdr.command('configure [port]')
  57. .description('Configure Wiki.js')
  58. .action((port) => {
  59. port = port || 3000
  60. let spinner = ora('Initializing interactive setup...').start()
  61. require('./configure')(port, spinner)
  62. })
  63. cmdr.parse(process.argv)
  64. if (!process.argv.slice(2).length) {
  65. cmdr.help()
  66. }