Search code examples
cronpm2

How can I get PM2 to load a new cron_restart?


I have a PM2 server running an ecosystem config file with certain jobs using the cron_restart functionality. I had one job configured as 0 6 * * * (every day at 6:00) and changed it to 0 10 * * * (every day at 10:00). I then restarted the ecosystem like this:

pm2 startOrReload ecosystem.config.js --update-env

The job still fired at 6:00 every day. So I tried this:

pm2 restart ecosystem.config.js

Still 6:00.

How do I have to restart PM2 to get it to refresh/reload the new cron_restart?


Solution

  • The --update-env flag notify pm2 to refresh ENV vars, so if you just update your ecosystem file, this flag just do nothing.

    To change your cron value first issue a pm2 list command and identify the task number you want to update.

    Then issue this command: pm2 restart 0 --cron-restart="0 10 * * *". In this example i assume you process ID is "0".

    Also update your ecosystem file and don't forget to issue a pm2 save command to save your configuration.