I use PM2 to run my node.js app. It works fine, however, sometimes my web hosting provider WebFaction (hello!) kills all the processes on my part of the shared server when my app goes beyond the memory limit (it's actually a java-based neo4j graph database doing that and I'm working on resolving this issue).
When this happens, PM2, for some reason thinks it is still running, even though my app is not online (while the database is restarted using a cron).
How do I make sure PM2 "knows" when something like this happens and restarts my node.js app even if it thinks it's still running?
I generally use something like monit to keep the process running. The basic idea is to have a cronjob which runs every minute and starts PM2 if it isn't running.
You will want to configure PM2 (or whatever you use for this) to either manage the process running in the foreground (like SupervisorD or SystemD), or monitor a PIDfile so that it can confirm that the process is actually running and start it if not. I don't know the specifics of how to do this in PM2 (never used it), but you can do this in SupervisorD or Monit.