How to disable/stop a pm2 module?
Asked Answered
C

2

16

Is it possible to stop or disable a pm2 module ? I did install the pm2-logrotate module but recently the community found an issue which is affecting our services and we need to stop or disable the module in top priority.

The module is continuously restarting and the node application in is production. So we cannot just stop the pm2 and look for a fix.

nodejs version: "4.8.2"
pm2 version "2.7.2"
pm2-logrotate version "2.4.0"
OS-Release: "Raspbian Stretch"


$ pm2 describe pm2-logrotate | grep -i script
│ script path       │ /home/user/.pm2/node_modules/pm2-logrotate/app.js │
│ script args       │ N/A                                                     │
│ script id         │ 0                                                       │
$ pm2 describe pm2-logrotate | grep -i id
 Describing process with id 0 - name pm2-logrotate
│ pid path          │ /home/user/.pm2/pids/pm2-logrotate-0.pid          │
│ script id         │ 0                                                       │
$ cat /home/user/.pm2/pids/pm2-logrotate-0.pid
7723
Club answered 16/4, 2018 at 0:14 Comment(1)
Basically, as per the pm2 documentation npmjs.com/package/pm2, pm2 stop all (stops all apps), pm2 stop 0 (where 0 is the id of a process) should work in your case.Dispossess
W
21

You can do pm2 describe pm2-logrotate. This will return alot of information. What you are looking for is script id

│ interpreter       │ node
│ interpreter args  │ N/A
│ script id         │ 0     
│ exec cwd          │ /home/user/.pm2/modules/pm2-logrotate/node_modules/pm2-logrotate
│ exec mode         │ fork_mode 
│ node.js version   │ 8.11.1

Now you know that the AppId is 0 so you can do

pm2 stop 0

and the module will stop.

You can always uninstall using

pm2 uninstall pm2-logrotate

Wolverhampton answered 16/4, 2018 at 8:21 Comment(4)
It does not have script id (it is 0). I found the pid path, which is a file with the value 7723. Do you think it can be safe to execute the pm2 stop 7723?Club
```$ pm2 describe pm2-logrotate | grep -i script │ script path │ /home/user/.pm2/node_modules/pm2-logrotate/app.js │ │ script args │ N/A │ │ script id │ 0 │ $ pm2 describe pm2-logrotate | grep -i id Describing process with id 0 - name pm2-logrotate │ pid path │ /home/user/.pm2/pids/pm2-logrotate-0.pid │ │ script id │ 0 │ $ cat /home/imagineing/.pm2/pids/pm2-logrotate-0.pid 7723Club
Did you try pm2 stop 0. The first app takes id 0. If this module is the first think you installed in a fresh pm2 then it will have id 0. Dont temper with pid. Even if you kill it, pm2 will create a new process.Wolverhampton
Thanks. You fixed my issue.Club
U
0

You want to kill the process? If so you can use the command:

pm2 kill filename.js
Ubangi answered 16/4, 2018 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.