1

I've tried many things but cron just won't restart pm2. I set the crontab -e with:

SHELL=/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin

*/10 * * * *  /usr/bin/node /usr/bin/pm2 restart all

And the I type:

cat /var/log/cron.log

And it says:

Apr  2 01:00:01 fatsecret CRON[8202]: (peteblank) CMD (/usr/bin/node /usr/bin/pm2 restart all)
Apr  2 01:00:01 fatsecret CRON[8201]: (peteblank) MAIL (mailed 78 bytes of output but got status 0x004b from MTA#012)
Apr  2 01:10:01 fatsecret CRON[8454]: (peteblank) CMD (/usr/bin/node /usr/bin/pm2 restart all)
Apr  2 01:10:01 fatsecret CRON[8453]: (peteblank) MAIL (mailed 78 bytes of output but got status 0x004b from MTA#012)

So it looks like its restarting every 10 minutes, but its not.

Romeo Ninov
  • 3,195
  • 2
  • 13
  • 16
pete
  • 21
  • 4

2 Answers2

1

So it turns out pm2 has an inbuilt cron feature. So I ran

pm2 restart 0 --cron "*/10 * * * *"
Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
pete
  • 21
  • 4
0

The best way to deal with cron jobs is to create specific script like this:

#!/bin/bash

. ~/.bashrc
/usr/bin/node /usr/bin/pm2 restart all

This script will load the environment variables which are required to run node and run the script in cron:

*/10 * * * *  /path/to/script

Do not forget to change ~/.bashrc with the absolute path to this file

Romeo Ninov
  • 3,195
  • 2
  • 13
  • 16