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?
Related
I have a NodeJS server written in Typescript, and I'm using supervisor to run this app in the background in production. However, when I type supervisorctl stop myapp, the process stops, but the node process is still running in the background and the site is live. How do I stop the given nodejs process with supervisor?
If supervisorctl stop doesn't stop your node process, you can actually set the stopsignal to one of following values: QUIT, KILL
In the config file '/etc/supervisor/conf.d/*.conf' add the following:
stopsignal=KILL
For more details check this.
I don't have any errors in my node app, but it stops after some requests. Though i have enabled the logs and checked, its showing on different requests.
Is it possible to start the node app whenever it is stopped ?
Currently i am using this to start the node app
To start the app
nohup npm start &
And to find the process id
ps aux | grep node
And to kill certain process
kill -9 PID
I don't want to leave the app stopped. It should be ever running. So, Is it possible to start the app whenever it gets stopped.
Thanks
You can use PM2 to monitor and restart your app for you.
By default if you run your app with PM2 it will auto-restart it if it crashes.
npm install pm2#latest -g
pm2 start index.js
PM2 can also be used to run multiple instances and has commands to stop/restart individual ones.
You can get the process PID using pm2 list as well.
More robust use case:
Start up your app by having PM2 run 'npm start' and also give it a name to refer to it later (it will auto restart if it exits/crashes)
pm2 start npm --name="mySuperApp" -- start
Later you make some changes and want to restart it:
pm2 restart mySuperApp
Eventually you want to stop the app:
pm2 stop mySuperApp
you can use nodemon
installing it with npm install -g nodemon
and running your code like this : nodemon index.js
Finding more documentation here
It will run until your app encounter an error but you can restart it with rs in your console
In pm2 node app manager, what is the difference between stop and delete app. I know that delete app deletes the app, from the pm2:s control, but what does stop app do? They both will set node server to offline.
My problem is that during deployment, if I want to pull code, and then restart the node server, then which pm2 commands to use? What I have done now is first pm2 stop app -> pull code -> pm2 start app. But how do I know that the app.js is really updated? What if stop puts the app in memory, and loads it there? So after start, it will start the previous version, and not from the code that was pulled.
Stop command keeps the app in the Apps list, delete command not.
You can see the Apps list with the command:
pm2 status
So if you stopped, you can restart your app just by its name.
I think the command you want is:
pm2 reload [AppName]
Just replace the files and then run the command.
Source:
http://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/
You can handle the reload signal inside you app, what could be interesting in production. More info:
http://pm2.keymetrics.io/docs/usage/signals-clean-restart/
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
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.