6

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.

Braiam
  • 1
  • 11
  • 47
  • 78
AJ.
  • 16,368
  • 20
  • 95
  • 150

2 Answers2

7

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/

user1852788
  • 4,278
  • 26
  • 25
6

use

$ pm2 delete [id]

you can retrieve the [id] using

$ pm2 ps
cweigel
  • 1,473
  • 16
  • 20
  • 1
    or `pm2 delete app_name` – Raine Revere Jun 17 '23 at 13:29
  • 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. – WEBjuju Aug 16 '23 at 17:27
  • 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. – cweigel Aug 17 '23 at 07:25