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.
So it turns out pm2 has an inbuilt cron feature. So I ran
The best way to deal with
cron
jobs is to create specific script like this:This script will load the environment variables which are required to run
node
and run the script in cron:Do not forget to change
~/.bashrc
with the absolute path to this file