How to remove pm2 from startup (on mac)
Asked Answered
E

6

10

I experimenting with pm2, which is a process manager for node.js applications. I tried their pm2 startup utility which generates and installs a startup script for pm2 when the system restarts.

I tried this on my mac, and it works flawlessly. The pm2 automatically restarts and spawns up all my node scripts.

However now, I am done experimenting and how do I remove this from my startup? I wish pm2 came with a similarly simple utility to uninstall itself from startup.

I am aware that it is using launchd on mac to restart the process. I noticed that it installed a io.keymetrics.PM2.plist file under /Users/<username>/Library/LaunchAgents directory.

Is it as simple as just deleting this file? or is it doing something more intrusive , and needs a more graceful uninstall?

It internally uses the following command to install the startup script

   sudo env PATH=$PATH:/usr/local/bin pm2 startup darwin -u shaunak
Emersed answered 10/2, 2015 at 5:21 Comment(0)
S
7

pm2 unstartup works fine on Ubuntu 16.04 which internally uses the following command:

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 unstartup systemd

Same should work on Mac as well (but the internal command will look a little different).

Stylolite answered 26/1, 2017 at 22:21 Comment(1)
pm2 unstartup cool!Pulley
C
6

If your want to stop the whole pm2 startup process make :

pm2 unstartup

If you just want to remove one app make :

pm2 stop yourapp //if needed
pm2 delete yourapp
pm2 save

It might be too late for you, but maybe it will be useful for someone else ...

Conrado answered 9/1, 2018 at 13:18 Comment(0)
C
2

First, get a list of all running agents using:

launchctl list | more

Or, if pm2 agent goes by the same name:

launchctl list | grep pm2

Then once you have the name of the pm2 agent that is part of launchd, execute:

sudo launchctl remove <pm2-agent-name>

And that's it. If you want to include an agent in the future again, you can do it by:

sudo launchctl load <agent-name>

Clarita answered 10/2, 2015 at 6:27 Comment(4)
Thanks for the answer, but the io.keymetrics.PM2.plist is not showing up in the list that shows up on launchctl list.. do you think it shows up in this last with some other name? I tried grep on pm2 and keymetrics, also tried manually looking through the list after filtering out apple ones..Emersed
Are you sure you have looked at the list closely ? because it should be there ...Clarita
yep, double checked :(Emersed
I used 'pm2 startup' as described in the pm2 docs linked in my question. I have updated the question and added the command it used internally.Emersed
E
1

OK, this has worked for me:

I deleted two files:

  • /Users/<username>/Library/LaunchAgents/io.keymetrics.PM2.plist
    This one registers the command pm2 resurrect at reboot.

  • /Users/<username>/.pm2/dump.pm2
    This last one I assume is created by pm2 dump and without this info even if PM2 is being resurrected at reboot there is nothing to resurrect?

Anybody found a more elegant way to do this?

Ence answered 18/9, 2015 at 9:51 Comment(0)
M
0

Use launchctl unload.

launchctl -w unload ~/Library/LaunchAgents/io.keymetrics.PM2.plist
Menses answered 15/2, 2015 at 6:5 Comment(2)
The file is present, but i get error saying 'launchctl: Error unloading: io.keymetrics.PM2'.. I tried sudo too..Emersed
launchctl -w load ~/Library/LaunchAgents/io.keymetrics.PM2.plist then again unload that file.Menses
E
0

To remove pm2 from startup on Mac OS :

  • Change the CURRENT_USER by your mac user name.
  • Run th following command:
sudo env PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 unstartup launchd -u m --hp /Users/CURRENT_USER
Embrey answered 15/5, 2020 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.