一般是开一个ssh
然后:
node t.js
如果这个ssh关闭,node也关闭了
如何让node t.js以守护进程运行啊???
10 回复
之前我在小田那里得到了一个更好的方法,这也是Joyent官方所推荐的:
var cluster = require('cluster');
if (cluster.isMaster) {
//Fork a worker to run the main program
for (var i = 0; i < 2; i++) var worker = cluster.fork();
} else {
//Run main program
require('./app.js');
console.log('worker is running');
}
cluster.on('death', function(worker) {
//If the worker died, fork a new worker
console.log('worker ' + worker.pid + ' died. restart...');
cluster.fork();
});
这个是我的MoeStream的保护进程,我加了一些注释,以便大家使用。