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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With