2016-12-29 2 views
1

bitcoind 데몬 명령을 시작하고 계속 모니터링하는 node.js 코드를 작성해야합니다. 충돌이 발생하면 프로세스가 다시 시작되어야합니다.node.js 코드로 크래시가 발생한 경우 비트 코인 데몬을 다시 시작하십시오

forever, forver-monitor, pm2과 같은 명령 줄 npm 모듈이 있다는 것을 알고 있지만 어떻게 코드에서 활용하고 전 세계적으로 시스템에 설치할 수 있는지 알고 싶습니다.

전자 응용 프로그램에서이 코드를 제공하기 때문에 최종 사용자는 자신의 컴퓨터에 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 시작 생각 프로세스를 포 그라운드로 유지하지 않고 백그라운드로 푸시? 영원히 모듈의 모니터에서 프로세스가 종료되었음을 보여 줍니까? 나는 잘 모르겠다.

도와 드릴까요?

미리 감사드립니다.

답변

0

프로세스가 종료되기 전에 child.start();으로 전화하는 것 같습니다.

영원히 모니터 설명서 how to spawning-a-non-node-process에서.

당신과 시도해야합니다 :

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() 
}); 
+0

YES! 이것은 문제를 해결합니다. :) – satinder