3

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?

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?

2 Answers 2

4

try forever.

npm install -g forever

https://github.com/indexzero/forever

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for the reply - I figured out that I mistakenly had upgraded to node 0.5.x. Further more I could not connect to mysql which caused a timeout after which the master thread died - without any errors written in the log. Once I downgraded to 0.4.9 and tested acccess to MySql so I was sure I could connect to 127.0.0.1 with the given user cluster worked just fine and stable. I can also detach from the terminal.
It sounds as if you had other problems, but @idefine's suggestion is good: forever is almost certainly a more robust solution than screen or nohup.
0

Looks like you're also setting

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

which probably doesn't exist on your linux server.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.