我需要编写一个node.js代码,它启动bitcoind守护进程命令并继续监视它,如果它崩溃,进程应该重新启动。
我知道有一些命令行npm模块,如forever、forver-monitor、pm2,但我需要知道如何在代码中使用它们,而不是在系统上全局安装它们。
原因是我将在电子应用程序中交付这段代码,最终用户不会在他们的机器上安装任何node.js或npm。
我使用了这段代码,它给出了一个错误:
代码:
var forever = require('forever-monitor');
  var child = forever.start(['./bitcoind'], {
    max : 1,
    silent : true
  });
  child.on('exit', function () {
    console.log('bitcoind has exited');
  });
  child.start();错误:
CONSOLE$ ps aux | grep bitcoind
satinder         32579   0.0  0.0  2432804    808 s001  S+    5:54pm   0:00.00 grep bitcoind
CONSOLE$ node test.js 
/Users/satinder/example/node_modules/eventemitter2/lib/eventemitter2.js:290
          throw arguments[1]; // Unhandled 'error' event
          ^
Error: Cannot start process that is already running.
    at /Users/satinder/example/node_modules/forever-monitor/lib/forever-monitor/monitor.js:158:26
    at doNTCallback0 (node.js:428:9)
    at process._tickCallback (node.js:357:13)
    at Function.Module.runMain (module.js:459:11)
    at startup (node.js:136:18)
    at node.js:972:3
CONSOLE$ ps aux | grep bitcoind
satinder         31931   0.1  0.3  2516556  23964 s000  SN    4:58pm   0:01.25 ./bitcoind
satinder         31939   0.0  0.0  2450212    832 s000  S+    4:58pm   0:00.00 grep bitcoind
CONSOLE$ 我认为原因是bitcoind在启动时没有将进程保持在前台,并将其推送到后台?而从永久模块的监控器上看,进程退出了吗?我没有把握。
有谁能帮忙吗?
提前谢谢。
发布于 2016-12-29 11:40:33
在进程终止之前,您似乎调用了child.start();。
来自永久监控文档如何生成非节点进程。
你应该试着:
const forever = require('forever-monitor');
const child = forever.start(['./bitcoind'], {
  max : 1,
  silent : true
});
child.on('exit', function () {
  console.log('bitcoind has exited');
  child.start()
});https://stackoverflow.com/questions/41373438
复制相似问题