I created my node js server using swagger via:
swagger project create <project-name>
But when I'm trying to launch the server using pm2 as follows:
pm2 start app.js
it's crashing because of too many unstable restarts. Below is the error message:
Script /path/to/app.js had too many unstable restarts (16). Stopped.
"errored"
Its a known issue and it can be fixed if we change the FD0 pipe in ForkMode from "ipc" to "ignore".
For more details please refer to this issue thread on github: PM2 crashes due to many unstable restarts
Related
I have been using pm2 to manage my node apps for a while. In deployment steps, pm2 restart is added after deployment finished. But it throws unhandledrejection event in promise js and service becomes unavailable.
when i manually restart pm2 manually issue vanishes. we are using same deployment steps on qa and production. But this issue of taking manual restart of pm2 is only happening at qa environment.
we have tried restart pm2 script in cron job as well but that also doesn't solved our issue.
I suspect may be due to diff in npm, node versions at prod and qa env, the behaviour is different.
I have my NodeJs server hosted on DigitalOcean.The server worked well for few days after which it stopped due to pm2 starting again and again.
This is a screenshot of my logs after starting it with pm2 start app.js
However, if I simply start my server using node app.js it works fine.
My code for listening on server is
I have not found any suitable answer for this problem.If more description to this problem is required then let me know.
This mainly happens when your server does not kill previously running processes.These processes keep on running and they consume whole memory causing memory leak.
Process killing can be done using following code
process.on('SIGTERM', function handleSigterm() {
server.close();});
this will kill all the previous running process
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 ?
Run you app with pm2 instead of forever. Pm2 will restart the node server even after uncaught exceptions.
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.
I am running a forever process for Node.js server but after one day the server stops the process.My server is running on Ubuntu platform. I have done the following process:
First I installed npm install forever and ran the command forever start server.js. I need the server to run for all the time but after one day I am seeing the server stops working.
Please help me to resolve this issue.
I would like to suggest that you try PM2 instead. Here's the short tutorial I wrote about it: http://www.nikola-breznjak.com/blog/nodejs/using-pm2-to-run-your-node-js-apps-like-a-pro/.
edit:
As per StackOverflow's policy I'm including the content from the post here also:
Running your Node.js application by hand is, well, not the way we roll. Imagine restarting the app every time something happens, or god forbid application crashes in the middle of the night and you find about it only in the morning – ah the horror. PM2 solves this by:
allowing you to keep applications alive forever
reloading applications without downtime
facilitating common system admin tasks
To install PM2, run the following command:
sudo npm install pm2 -g
To start your process with PM2, run the following command (once in the root of your application):
pm2 start server.js
As you can see from the output shown on the image below, PM2 automatically assigns an App name (based on the filename, without the .js extension) and a PM2 id. PM2 also maintains other information, such as the PID of the process, its current status, and memory usage.
As I mentioned before, the application running under PM2 will be restarted automatically if the application crashes or is killed, but an additional step needs to be taken to get the application to launch on system startup (boot or reboot). The command to do that is the following:
pm2 startup ubuntu
The output of this command will instruct you to execute an additional command which will enable the actual startup on boot or reboot. In my case the note for the additional command was:
sudo env PATH=$PATH:/usr/local/bin pm2 startup ubuntu -u nikola
I have a SailsJS app set up on a Webfaction server. Everything works nicely (site can be accessed through browser, console works) when I run the app via any of the following commands, with and without the --prod param:
sails console,
sails lift,
node app.js
However, when I try to run the app with forever using forever app.js I get a 502 error, as if nodejs server isn't even running. When I run forever list I can see app.js listed among running processes.
How can I have my app run with forever?
Forever is considered outdated by many in the Node community, and thankfully, has been replaced by several other fantastic (dare I say, better) tools.
If you're running a newer flavor of Ubuntu, you can always install systemd and kick off the application that way. If you're seeking something more streamlined, Phusion Passenger might be your ticket. It has a long track record of successes, and I wouldn't hesitate to toss it into production.
I managed to solve this issue; the problem occurred due to SailsJS migration prompt which shows up when you start the server. Running app.js with forever worked, but the server didn't start because the script hanged waiting for a prompt reply. If you encounter this issue just make sure you have your migrate option set in model config to avoid running into migration prompt.