2012-11-02 31 views

回答

3

好像沒有建立,所以我用一個pid文件永遠監視器,以便在發生錯誤時重新啓動我的app.js腳本。 看起來像是在工作。 你需要做的是NPM安裝永遠 寫server.js:

var forever = require('forever'), 
    child = new(forever.Monitor)('app.js', { 
     'silent': false, 
     'pidFile': '/var/run/app.pid', 
     'watch': false, 
     'options': ['8383'], // Additional arguments to pass to the script, 
     'sourceDir': '.', // Directory that the source script is in 
     'watchDirectory': '.',  // Top-level directory to watch from. 
     'watchIgnoreDotFiles': true, // whether to ignore dot files 
     'watchIgnorePatterns': [], // array of glob patterns to ignore, merged with contents of watchDirectory + '/.foreverignore' file 
     'logFile': 'logs/forever.log', // Path to log output from forever process (when daemonized) 
     'outFile': 'logs/forever.out', // Path to log output from child stdout 
     'errFile': 'logs/forever.err' 
    }); 
child.start(); 
forever.startServer(child); 

,然後用運行 - 節點server.js(從我〜/目錄下的NodeJS運行) 仍是PID文件應該在/ var/run中不存在,很奇怪,但我不需要monit了。 我仍然不明白爲什麼我應該另外使用暴發戶(如所有相關的帖子建議)無論如何,當我試圖運行暴發戶它不起作用

5
在您的應用程序

你可以得到process.pid所以

var fs = require('fs'); 
fs.writeFile("/tmp/pidfile", process.pid); 

當前PID號碼,你tmp中得到一個pidfile進程文件

+0

謝謝,但我需要的過程pidfile不是pid號 – Liatz

+1

也許我不會不明白你想要什麼,但是pidfile只是一個帶有PID號碼的文件。 –

+0

但當進程重新啓動時,pid會改變。無論如何,這是monitrc配置需要的。我必須給它pid文件路徑。 – Liatz