PM2 systemd service correctly reloads processes on restart, but loses them all on reboot
The systemd service scripts for PM2 work correctly when starting or stopping the PM2 service, but all process information and pm2.dump is wiped when the server is rebooted and the PM2 service is started automatically. May be related to #2377 #2559
Expected behaviour
After pm2 save is run, when the pm2 systemd service is restarted, processes are correctly restarted. When a server reboot occurs, the pm2 systemd service should still restart the processes that were previously saved.
Actual behaviour
After a server reboot, no processes are restarted. In addition, the pm2.dump file seems to be overwritten and only contains an empty array [].
Steps to reproduce
- Start a process using
pm2 start pm2 savereboot- Login and
pm2 statusorsystemctl status pm2- process list will be empty pm2.dumpfile will only contain empty array[]
Software versions used
OS : CentOS 7.3
node.js : 4.4.4
PM2 : 2.2.3
PM2 Log output
Use the command: tail --lines 50 ~/.pm2/pm2.log
Don't have an easy way of copying the logs from another environment, but all the logs say after a reboot are "New PM2 Daemon started" with the correct environment settings and a "Stopping PM2" entry right afterwards.
cf CONTRIBUTING.md for more informations
Started a clean VM with Centos 7 and the exact same version as you and its working both after killing the PM2 process and after a reboot. Are you sure that you don't have cron doing thing at the shutdown ?
Cron isn't doing anything -- my crontab is empty.
I have another coworker who is experiencing the same issue with a CentOS 7 VM created via ansible. He only just noticed it now since he rebuilds instead of reboots.
My current workaround right now is making dump.pm2 immutable via chattr +i but that's really just a hack until I figure out what's causing dump.pm2 to be emptied out. It's almost like an additional save is taking place when nothing is running that I don't know about.
- Can you check that only one daemon is running before the
reboot:ps aux | grep PM2? - What are the permission on the file (maybe a daemon running from somewhere else can overwrite the file) ?
- Could you try giving me the content of the service config
/etc/systemd/system/pm2.service?
Can you check that only one daemon is running before the reboot : ps aux | grep PM2?
Only one is running...
node /usr/lib/node_modules/pm2/bin/pm2 resurrect --no-daemon
What are the permission on the file (maybe a daemon running from somewhere else can overwrite the file) ?
A stat on dump.pm2 shows me Uid: 0/root Gid: 0/root Access: (0644/-rw-r--r--) Context: unconfined_u:object_r:admin_home_t:s0
Could you try giving me the content of the service config /etc/systemd/system/pm2.service?
I'd have to retype the entire file from scratch but I think the relevant lines you want are:
...
Environment=PM2_HOME=/root/.pm2
...
ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect --no-daemon
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill
Definitely weird, could you add a DEBUG=* to the ExecStart and ExecStop entries and get the logs inside the journalctl to see if there is any issue.
Added DEBUG=* as another Environment setting (ExecStart and ExecStop complained) and somehow it's magically working. No idea why. Then took it out again and it's still working.
Checked coworker's server and it ended up he didn't have that problem (he wasn't doing a pm2 save first).
I'm wondering if it's because I had an init.d script lingering from an old version of PM2 that I later removed (pm2-init.sh) and things were getting clobbered a few days ago until I removed it, but thought the problem was still happening. Perhaps it would make sense to make sure there aren't any other conflicting startup scripts on install.
Actually we have a check here but only for the unstartup method, guess we could make one if anyone has the same issue again.
@vmarchaud it seems like my problem https://github.com/Unitech/pm2/issues/3485