16

I have a pm2 process named app that was used to test the configuration.

I noticed app was starting when the system rebooted, and it was causing errors with the real application.

I ran:

 pm2 delete app

then I ran:

 pm2 list

and it didn't show app.

When I reboot my system, the app is still there and it is running. I attempted to find information on where the config file is online, and there is no information other than creating a template config file. Where should the config file that pm2 reads on startup be located on an Ubuntu system, or why isn't delete working as I intend? Is there another method or command I can use to remove a pm2 process or am I looking at this incorrectly?

David Kamer
  • 2,677
  • 2
  • 19
  • 29

2 Answers2

40

If you use "pm2 delete {appname}" to delete the last app

pm2 delete app

when you run

pm2 save

It will show

[PM2] Saving current process list...
[PM2] Nothing to save !!!
[PM2] In this case we keep old dump file. To clear dump file you can delete it manually !

Which means, actually, the last app information is still not deleted.

The solution is to create a new dump file.

pm2 cleardump

Then, the app will be deleted permanently.

You can check the pm2 file to see what's actually saved into dump file.

/home/ubuntu/.pm2/dump.pm2
Robin Ding
  • 741
  • 6
  • 9
  • 2
    about using `pm2 save --force`? – ahong Mar 12 '20 at 11:29
  • 1
    I haven't tried option --force, but based on https://pm2.keymetrics.io/docs/usage/application-declaration/, seem "--force" is for starting a process. I will try and update here. Thanks. – Robin Ding Apr 03 '20 at 21:40
  • --force option works! pm2 save --force [PM2] Saving current process list... [PM2] Successfully saved in /root/.pm2/dump.pm2 – Dmytro Sukhovoy Feb 16 '21 at 16:19
5

Saving some time for those who may or may not use pm2 regularly and struggle when searching for an answer on this:

You have to save the edits for pm2:

pm2 save

after making any changes. Unlike most Unix style settings interfaces, pm2 requires you to save your changes from the running version to the config file.

Hope this helps someone even though it is simple! I don't use PM2 all the time and it was really frustrating to not find any answers on SO or anywhere else that referred to the need to use pm2 save when deleting a process.

David Kamer
  • 2,677
  • 2
  • 19
  • 29