The following isn't for mission-critical systems, but it's been working so
well for us and is so simple that I thought I'd share. We use nodemon
(https://github.com/remy/nodemon) to start our node server. It's just file
watcher that restarts node if a source file changes, normally used for dev.
It is much smaller and has fewer moving parts than forever. node-dev is a
similar tool (https://github.com/fgnass/node-dev) that many people like
that does basically the same thing.
our startup script is something like this:
nohup nodemon <app> >>/var/log/app.log 2>&1 &
Then in our main app startup function, we have this charming little hack:
process.on('uncaughtException', function(err) {
console.error(err.stack||err)
if (serverStarted) {
fs.writeFileSync('./crash.js', '// App crashed ' + Date() + '\n\n' +
err.stack)
}
process.exit(1)
})
The vast majority of our server crashes are due to bugs in our code, not
external problems like hardware, and this works fine for those. If my job
were on the line to keep the server alive no matter what I would figure out
upstart or monit, but they both make my head hurt, and for the 90% case,
this does the job.
Cheers!
-George
On Monday, March 12, 2012 8:02:20 AM UTC-7, Flavio Del Bianco wrote:
>
> Hi, I'm learning nodejs and I had a doubt in how I keep alive a
> webserver without running it everytime like $ node myserver.js? and
> how it can connect alone every time the server get on like it does
> apache.
On Monday, March 12, 2012 8:02:20 AM UTC-7, Flavio Del Bianco wrote:
>
> Hi, I'm learning nodejs and I had a doubt in how I keep alive a
> webserver without running it everytime like $ node myserver.js? and
> how it can connect alone every time the server get on like it does
> apache.
On Monday, March 12, 2012 8:02:20 AM UTC-7, Flavio Del Bianco wrote:
>
> Hi, I'm learning nodejs and I had a doubt in how I keep alive a
> webserver without running it everytime like $ node myserver.js? and
> how it can connect alone every time the server get on like it does
> apache.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en