4

Gurus of SO

I am running Node.js as a daemon using monit & it turns out that it fails every 60 seconds on the dot. Here's my monit.log

root@mybox:/etc/monit# tail -f /var/log/monit.log
[UTC Sep  4 12:07:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:08:50] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8000] via TCP
[UTC Sep  4 12:08:50] info     : 'nodejs' trying to restart
[UTC Sep  4 12:08:50] info     : 'nodejs' stop: /sbin/stop
[UTC Sep  4 12:08:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:09:50] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8000] via TCP
[UTC Sep  4 12:09:50] info     : 'nodejs' trying to restart
[UTC Sep  4 12:09:50] info     : 'nodejs' stop: /sbin/stop
[UTC Sep  4 12:09:50] info     : 'nodejs' start: /sbin/start
[UTC Sep  4 12:10:50] info     : 'nodejs' connection succeeded to INET[127.0.0.1:8000] via TCP

Here's my monit config from monitrc

set logfile /var/log/monit.log

check host nodejs with address 127.0.0.1
    start program = "/sbin/start nodeapp"
    stop program  = "/sbin/stop nodeapp"
    if failed port 8000 protocol HTTP
        request /
        with timeout 10 seconds
    then restart

Am I doing something wrong in this configuration or is there some other reason Node seems to fail so regularly? Where else should I look to pinpoint this problem?

Thank you.

iUsable
  • 361
  • 3
  • 13

2 Answers2

1

First make sure that the application doesn't crash after multiple requests. A good way to do is this with ab (apache benchmark). If you're sure that your code is stable then it likely an issue with Monit.

ab -c 10 -n 1000 http://127.0.0.1:8000/
Ryan Olds
  • 4,847
  • 28
  • 24
1

Seems you want to run NodeJS as service using Monitrc. If you use Ubuntu, then you should consider using Runit. I have use it on Amazon EC2 nearly 3 month without any restart and it's stable.

Here are guide for running NodeJS as service :

http://www.yodi.me/blog/2011/09/05/run-nodejs-in-ubuntu-11-dot-04-ec2-with-user-permission-and-run-as-service/

yodi
  • 942
  • 8
  • 10