pm2 kills everything and can not be restarted without a server reboot - node.js

Twice now all apps I have been running through pm2 has been stopped for no apparent reason to me. All apps where started with pm2 start app.js -n prettyname which works fine for a few days until this.
No I idea why it stops. But doing any pm2 command like the above in the screenshot, starting, restarting or stopping results in the same. [PM2] Spawning PM2 daemon
Is there a way to restart the apps without restarting the server?
node 0.10.32
pm2 0.15.10

Try below command to restart all pm2 apps,
pm2 restart all

Related

Nodejs API doesn't work after reboot centos server

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.

Why pm2 is fine, but pm2 logs is not?

I'm using pm2 to keep tracking of what I do on backend with NodeJS. Until yesterday it all worked perfectly fine, but today, even if pm2 server is working fine (i can start the project server and i can navigate), pm2 logs just stopped for no reasons.
Here you can see the version I'm using (i already updated PM2 both on project and local as i find in other answers).
I usually use the command
pm2 start process.json
pm2 restart 0 --watch
pm2 restart 0
And in other prompt instance, for the logs i use
pm2 logs
For some reason PM2 is just tailgating the last 15 lines but it doesn't work real time like it used to do
I didn't find this exact problem on other questions (only questions about pm2 not working at all, but not about pm2 working half way). Any suggestions?
Apparently the version of node and pm2 were the source of the problem. I used this command to run pm2 using the node version explicitly
pm2 start process.json --interpreter=/home/ken/.nvm/v10.15.1/bin/node
This way you force pm2 to use settings for the version of node you've installed in your machine. Now both server and logs works fine.

Can't stop node.js app started with pm2 process manager

I want to rebuild my node+vue.js app to update the changes I made. The app was started with pm2, but the problem is that I can't see anything when I do pm2 ls. The list is empty. On the other hand, the node app is running. I tried to kill it with pid, but it is restarting immediately.
Any suggestions?

Getting error when trying to launch node.js app with PM2 Cluster

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

Start Node JS application when server reboots with pm2

I am trying to use the module pm2 to start my node js app everytime the server boots.
I have used the command pm2 startup ubuntu but each time I restart the server, my application is not running and I have to start it manually again.
Any ideas what is causing this issue?
Make sure you do save your processes:
pm2 start app.js
pm2 startup ubuntu
pm2 save
Once you have started the apps and want to keep them on server reboot
do: pm2 save
Source: https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#startup-script
Go to your server directory and use the following commands:
pm2 start <your_app_name.js>
pm2 startup ubuntu
pm2 save

Resources