0

Currently, I have a NodeJS service running on my server. It provides a RestAPI thanks to HAPI.JS

This service run permanently with forever executed in upstart script but I got some trouble.

Sometimes, the service have an error like this :

Debug: internal, implementation, error 
    TypeError: Uncaught error: Cannot call method 'replace' of undefined....

At this moment, server is completly down and never restart :(

I need a 100% stable service that why I have to restart it when an error appears.

My Question :

How can I restart NodeJS Service with forever when errors occured ?

Community
  • 1
  • 1
Quentin DESBOIS
  • 123
  • 1
  • 1
  • 9
  • can you post the code that is throwing the error? – Clarkie Aug 26 '15 at 16:04
  • 1. Find the error trace 2. Can you place your forever command? – bluesman Aug 26 '15 at 16:19
  • This error was just an example. I able to fix it, this is not the problem. I may have other kind of error that occured and I can't forecast it that why I need to restart my process. – Quentin DESBOIS Aug 27 '15 at 07:17
  • my command is simple (in upstart or directly in command line) : - forever start restAPI/index.js - forever restart restAPI/index.js And then I look up the log in /root/.forever/MYUID.log – Quentin DESBOIS Aug 27 '15 at 07:21

2 Answers2

1

Run you app with pm2 instead of forever. Pm2 will restart the node server even after uncaught exceptions.

marekful
  • 14,986
  • 6
  • 37
  • 59
  • Ohhh it seems good. I will try it and I return my feeling about PM2. Thank You. – Quentin DESBOIS Aug 27 '15 at 07:18
  • You're welcome and happy day to the no commenter down-voter! :) – marekful Aug 27 '15 at 07:27
  • Woooww, I set up PM2 and it's a very powerful solution. I use KeyMetrics webpage to monit my bucket. It's amazing. May I take Premium account in few months. Thank you again Marekful ;) – Quentin DESBOIS Aug 27 '15 at 08:33
  • I assume the downvote is because your answer doesn't really answer the question. It's a perfectly valid real world solution but it by passes the actual problem. – Clarkie Aug 27 '15 at 08:43
0

If the process fails on startup then it won't restart automatically. You can configure the minimum uptime --minUptime flag.

You can then use the --watch flag to watch for changes of the fix.

However, the specific error you're receiving wouldn't normally stop the Hapi process which would suggest this isn't a forever issue.

Clarkie
  • 7,490
  • 9
  • 39
  • 53