How can I completely stop a pm2 managed application?
Asked Answered
P

2

7

Say I have a pm2 process that runs every 5 minutes and takes less than a second to run:

pm2 start ./some-node-script.js --name some-node-script --cron "*/5 * * * *" --no-autorestart

Now say I want to completely stop execution of the job. If I issue pm2 stop some-node-script, I get this warning:

[PM2][WARN] App some-node-script stopped but CRON RESTART is still UP */5 * * * *

And then the job executes again on the next 5 minute interval. Is there a way I can stop the cron job from executing again? I've tried pm2 kill, but that kills every job being managed by pm2.

Porcine answered 24/7, 2020 at 15:41 Comment(0)
C
6

use

$ pm2 delete [id]

you can retrieve the [id] using

$ pm2 ps
Collado answered 20/8, 2020 at 13:59 Comment(3)
or pm2 delete app_nameEthelind
while i have plus one'd this, i'm curious now that i've deleted it... how might i put it back ? under pm2 help i don't see a pm2 add. maybe this is a simple question that rtfm would solve, but i'll post my curiosity in case an answer here would add value for others, too.Fraser
You would need to newly start the process / app the same way as you started it in the first place (e. g. using pm2 start ...). This usually will assign a new ID (counting up) to the process.Collado
M
8

To disable cron restart:

pm2 restart app_id --cron-restart 0

Then you can just

pm2 stop app_id

It will save app id.

https://pm2.keymetrics.io/docs/usage/restart-strategies/

Megalith answered 24/5, 2022 at 5:37 Comment(0)
C
6

use

$ pm2 delete [id]

you can retrieve the [id] using

$ pm2 ps
Collado answered 20/8, 2020 at 13:59 Comment(3)
or pm2 delete app_nameEthelind
while i have plus one'd this, i'm curious now that i've deleted it... how might i put it back ? under pm2 help i don't see a pm2 add. maybe this is a simple question that rtfm would solve, but i'll post my curiosity in case an answer here would add value for others, too.Fraser
You would need to newly start the process / app the same way as you started it in the first place (e. g. using pm2 start ...). This usually will assign a new ID (counting up) to the process.Collado

© 2022 - 2024 — McMap. All rights reserved.