I made a gRPC client in node and i start it through pm2 with a simple:
pm2 start --name myAppName
The gRPC client have some listener on.data, on.error on.end etc
All works well but sometimes the gRPC server trigger the on.end with an error and then the script stop.
Error: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)
I was expecting that by default pm2 job was to restart in that case but it seem not.
Do i needs to explicitely use a restart strategy like "--exp-backoff-restart-delay=100" when i start the app with pm2 for it to restart automatically in that situation? --watch option is not related here right? its only for file change restart is that correct?
Thanks in advance for the help.
Related
In my centos server, I have an API with node js and I started with pm2. pm2 status is online and It works correctly. but when server reboot, can't connect to the API although pm2 status is online.
I also try start node js like below
pm2 start index.js
pm2 startup
pm2 save
but It does not work until I restart pm2 ..
how can I fix it?
You have to do pm2 resurrect to start an application after "pm2 saving" it:
pm2 resurrect
Then put this command in a script file and configure it to run on server reboot. Read this Q and A for help. Also in this article there are some CentOS specific changes that need to be done.
I'm trying to deploy my NodeJS app. I tried npm forever and pm2, but I believe that my hoster restarts the server every night because my app is always offline the next day.
The thing is, that I have a shared hosting server on A2hosting and don't have root access, so these sudo commands don't work here... except you know how I can change that, haha...
I don't know what infos I need to provide for you to help me... so if you need to know something, tell me please!
Thank you so much!
I've used pm2 to do that.
npm install -g pm2
then you run the following command to ensure pm2 will run on startup:
pm2 startup
It will show you the command you have to run.
Finally, you initiate the process:
pm2 start server.js --name <service-name>
Freeze your process list:
pm2 save
More details on pm2 documentation: https://github.com/Unitech/pm2
in an Ubuntu Server, I am unable to run the node.js app in cluster mode using PM2.
The command I use is :
PM2 start server.js --name Server -i max
When I list the PM2 processes, I can see the Server has Error status.
I have tried looking into the log file generated by PM2 but it's empty.
I am however able to run the same server.js without the cluster mode using :
PM2 start server.js --name Server
doing PM2 Kill and starting all the services again was the solution to above issue.
You could also have used pm2 restart Server to restart it
If you use pm2 kill you will just kill all processes, to clean up afterwards i would recommend to use pm2 flush so all logfiles will be reset
I have gone through this same kind of situations but in my case pm2 is showing error status cause of error in my code.
use the below command
pm2 logs
pm2 logs command helped me by showing some hints to check where exactly the error is occured.
if everything works fine then pm2 list will show you the status online.
you can check the ports running by pm2(not only pm2 but all the process) using below command
sudo netstat -tulpn
I have a node chat application that needs to keep running on my server (ubuntu with nginx). The problem is that the application stops after a few hours or days.
When I check on the server I see that my pm2 list is empty.
The code I use to start my app:
pm2 start notification_server/index.js
It somehow looks as if pm2 is reset after a while. I also tried using forever, but then I run into the same problem. Is there some way to prevent the pm2 list from getting empty?
This is most likely an indication that your server is rebooting. When your server reboots, PM2 shuts down and deletes all Node instances from its "status" list.
You can perform the following steps to make PM2 relaunch your Node programs start back up on reboot:
Run pm2 startup and follow the directions (you will have to perform a sudo command; PM will tell you exactly what to do).
Through pm2 start, get your Node processes up and running just like you like them.
Run pm2 save to register the current state of things as what you want to see on system startup.
Source: http://pm2.keymetrics.io/docs/usage/startup/
Did you try checking logs $ pm2 logs for you application?
Most likely it will tell you why your application was terminated or maybe it just exited as it supposed to. You could find something like that there:
PM2 | App [app] with id [0] and pid [11982], exited with code [1] via signal [SIGINT]
This can tell you what happened. Without more details, it's hard to give you a better answer.
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.