Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PM2 resurrect not working on reboot - dump.pm2 being emptied

I'm trying to configure PM2 to daemonize a simple node.js server on centos. The init.d script executes, and there are no errors, but pm2 list returns an empty list, and the server is not starting.

Originally, I was attempting to start the process as a different user (for those interested, this can be done with modifications to pm2-init.sh). But due to the complication, I decided to first try to get it to run as root.

The strange symptom of the problem is that the dump.pm2 file is being emptied by some process, thus the pm2 resurrect has nothing to do. I set up pm2 to run on reboot as follows

$ pm2 startup centos
$ pm2 start /path/to/my/server.js
$ pm2 save

At this point, dump.pm2 had a large JSON object in it and the server is running. Then, running:

$ reboot
  ... wait and log back in
$ pm2 list

It was empty again, and so was the dump.pm2!

I'm not sure what process is clearing this file. I've tried reinstalling and re-running the startup script to no avail. Any help is greatly appreciated.

like image 470
Jamie Counsell Avatar asked Apr 15 '15 14:04

Jamie Counsell


1 Answers

As a temporary workaround, I set the dump file as immutable:

$ chattr +i /path/to/my/dump.pm2

This worked. Although not ideal, it is what I will use until I can determine why the dump.pm2 file is being emptied.

like image 86
Jamie Counsell Avatar answered Oct 04 '22 01:10

Jamie Counsell