简体   繁体   中英

Run PM2 cron only on a scheduled time

I run one of my node.js command using the following command:

pm2 start sample.js --cron "0 1 * * *" -- SAMP

But the problem is this program run twice. First one is when I execute the command and send one is at 1:00 AM(Which we want).

So my query is how can set the cron so that this program runs at only once (At 1:00 AM only).

My suggestion to you is to use crontab for this task. This is exactly what cron was designed for, and not what pm2 was designed for.

As the comment above states, the --cron option only specifies when the app should be restarted , --cron cannot be used to schedule the running of an app. In the cases where we need to run a node app on a specific time table and don't need all of the fancy pm2 capabilities of auto-restarting and clustering, we simply use crontab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM