2016-12-29 8 views
1

bitcoindデーモンコマンドを開始し、それを監視し続けるnode.jsコードを作成する必要があります。クラッシュした場合、プロセスが再起動する必要があります。node.jsコードでクラッシュした場合の再起動bitcoindデーモン

私はforever,forver-monitor,pm2のようなコマンドラインnpmモジュールがあることを知っていますが、私はそれらをコード内でどのように利用でき、それらをグローバルにシステムにインストールできないかを知る必要があります。

私はこのコードをElectron Appで提供するつもりであり、エンドユーザーは自分のマシンに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();と呼んでいるようです。

forever-monitorのマニュアルhow to spawning-a-non-node-processから。

あなたはしてみてください:YES

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

!これは問題を解決します。 :) – satinder

関連する問題