Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable run app when using --cron #5648

Closed
Stepashka20 opened this issue Jul 31, 2023 · 4 comments
Closed

How to disable run app when using --cron #5648

Stepashka20 opened this issue Jul 31, 2023 · 4 comments

Comments

@Stepashka20
Copy link

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 :(

@soshin1337
Copy link

same problem

@alexgalkin
Copy link

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.

@ultimate-tester
Copy link
Contributor

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

@Unitech
Copy link
Owner

Unitech commented May 24, 2024

Feature landed

Update PM2 to 5.4.0

$ npm install pm2@5.4.0 -g
$ pm2 update

@Unitech Unitech closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants