开发者

Node.js, express and cluster

开发者 https://www.devze.com 2023-03-19 11:40 出处:网络
I have setup a test of a Node.js server but how is the server best launched? My strategy for now is to use cluster (http://learnboost.github.com/cluster/). This mostly works really nice. I have the

I have setup a test of a Node.js server but how is the server best launched?

My strategy for now is to use cluster (http://learnboost.github.com/cluster/). This mostly works really nice. I have the following setup in my app.js file (created with express):

cluster(app)
.use(cluster.reload())
.use(cluster.reload('views', {extensions: ['.js', '.ejs']}))
.use(cluster.logger('logs'))
.use(cluster.stats())
.use(cluster.repl('/Users/testuser/work/1test/test.sock'))
.use(cluster.debug())
.use(cluster.pidfiles())
.use(cluster.cli())
.listen(3000);

It works on my Mac when i test locally. I launch it with the command

nohup node app.js &

But when I run on Linux and detach from the terminal the master dies - the working threads are still working. On the Mac it runs even when I close the terminal.

I read that it might be necessary to change the user, this can apparently be done in cluster with: .set('user', 'rambo')

Does anyone have a "best practice" for launching node.js as a "Daemon" with cluster so you can detach the terminal?开发者_如何学Go

If I change the user who should I be logged in as when I launch?

Should I use a program such as screen to detach from the terminal without killing any processes?


try forever.

npm install -g forever

https://github.com/indexzero/forever


Looks like you're also setting

.use(cluster.repl('/Users/testuser/work/1test/test.sock'))

which probably doesn't exist on your linux server.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号