pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

How to disable run app when using --cron

Open Stepashka20 opened this issue 2 years ago • 3 comments

I need to run my app at 6:00, and only at this time. However, when I run the simple command:

pm2 start app.js --cron "0 6 * * *"

pm2 launches the application immediately. Can I prevent this from happening? The feature of writing logs to 2 different files with a timestamp using the --out and --err options is very useful to me, which can't be done with a Linux cron :(

Stepashka20 avatar Jul 31 '23 19:07 Stepashka20

same problem

soshin1337 avatar Jan 20 '24 06:01 soshin1337

there is no option for this as far as I know. But I have added the following condition to app.js itself when I had similar requirement:

if (!process.env.prev_restart_delay && process.env.cron_restart) {
  console.log('skipping initial launch....');
  process.exit(0);
  return;
}

this will stop the process immediately but it still will be restarted by cron. Note you should also disable autorestart (--no-autorestart)

Not ideal, but works in my case.

alexgalkin avatar Mar 06 '24 21:03 alexgalkin

I'm going through the issues to find mentions about not auto-starting a new process, which I now created a PR for: #5780

ultimate-tester avatar Mar 08 '24 19:03 ultimate-tester

Feature landed

Update PM2 to 5.4.0

$ npm install [email protected] -g
$ pm2 update

Unitech avatar May 24 '24 12:05 Unitech