有人用 pandora.js 管理egg.js项目的嘛
发布于 4 个月前 作者 ddzyan 1143 次浏览 来自 问答

现在想对 nodejs 的服务进行进程管理与监控,选用了 pandora.js。根据官网的介绍,现在出现了2个问题。

  • 服务无法后台启动
  • 图形化界面无法启动

具体操作步骤如下: 系统:ubuntu 16.0.4

# index.js 文件
const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

node -v

cnpm i pandora -g 

pandora init ./index.js

# 服务前台运行
pandora start -d
npm i pandora-dashboard -g

pandora start --name dashboard `pandora-dashboard-dir` 
[Pandora.js] Switch current working dir to /home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora-dashboard
[Pandora.js] Actuator restful server started at http://127.0.0.1:7002
[Pandora.js] IPC Hub Server started
[Pandora.js] IPC Hub Client started at PID 15202
[Pandora.js] Indicator manager published on IPC hub at PID 15202
[Pandora.js] Error: Command failed: /home/james/.nvm/versions/node/v10.16.0/bin/node  -e 'require("/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js").ProcfileReconciler.echoStructure({"appDir":"/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora-dashboard","appName":"dashboard"}, "/tmp/0c4f9877-5077-4c1f-a319-5f5f059a5e96"); process.exit()'
/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora-dashboard/procfile.js:7
    pandora.service('dashboard', './dist/Dashboard').process('worker');
            ^

TypeError: pandora.service is not a function
    at module.exports (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora-dashboard/procfile.js:7:13)
    at ProcfileReconciler.callProcfile (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js:81:13)
    at ProcfileReconciler.discover (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js:65:18)
    at Function.echoStructure (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js:191:28)
    at [eval]:1:135
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at evalScript (internal/bootstrap/node.js:589:27)

Error: Command failed: /home/james/.nvm/versions/node/v10.16.0/bin/node  -e 'require("/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js").ProcfileReconciler.echoStructure({"appDir":"/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora-dashboard","appName":"dashboard"}, "/tmp/0c4f9877-5077-4c1f-a319-5f5f059a5e96"); process.exit()'
/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora-dashboard/procfile.js:7
    pandora.service('dashboard', './dist/Dashboard').process('worker');
            ^

TypeError: pandora.service is not a function
    at module.exports (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora-dashboard/procfile.js:7:13)
    at ProcfileReconciler.callProcfile (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js:81:13)
    at ProcfileReconciler.discover (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js:65:18)
    at Function.echoStructure (/home/james/.nvm/versions/node/v10.16.0/lib/node_modules/pandora/dist/application/ProcfileReconciler.js:191:28)
    at [eval]:1:135
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at evalScript (internal/bootstrap/node.js:589:27)

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)

7 回复

在git上问赛

egg项目大家都是用什么做进程管理和资源监控的呢? alinode,pm2还是其他呢?

你这问题描述文不对题啊:

  • 上面那个不是 Koa 代码么?不是 Egg
  • 看报错信息是 pandora 自己的 CLI 报错,都还没到框架那层。

Egg 进程管理自带了,监控和分析除了 AliNode 没有一个能打的。 PM2 这种只能单机看看几个小数据,跟 AliNode 根本不是一个层面的概念。

@atian25

  1. 好的,EGG代码量较多,不好上传,所以写了koa的代码
  2. alinode可以做资源监控,如果一台机器上部署了多个egg项目,egg的进程管理要如何实现呢,
  1. 所以问题很清晰,并不是 pandora + egg 启动不了 ,而是 pandora 自身有问题,可能是什么插件或依赖没装好吧。
  2. docker 化。 就算你没 docker 化,进程管理没什么需要搞的啊,egg 本身就帮你搞定了进程守护,你无非就需要 npm start 和 npm stop 来启动和关闭就够了。

@atian25 好的,感谢

回到顶部