Restart pm2 app every 12h with cron

南笙酒味 提交于 2020-01-13 08:19:28

问题


Tried this, but it doesn't work:

SHELL=/bin/bash
PATH=/usr/lib/node_modules/pm2/bin
* 0,12 * * * pm2 restart all

What am I doing wrong?


回答1:


Edit cron with crontab -e and add the following:

0 */12 * * * /usr/bin/node /usr/bin/pm2 restart all

For the schedule, use 0 */12 * * * for every 12 hours, or 0 0,12 * * * for 0:00 and 12:00 specifically. (Your schedule, * 0,12 * * *, would trigger every minute of hour 0 and hour 12, 0:00, 0:01, 0:02...)

For the command, as fedorqui mentioned, use the path to node followed by the path to pm2 and the pm2 options. Use which node and which pm2 to get the path to node and pm2.



来源:https://stackoverflow.com/questions/37514444/restart-pm2-app-every-12h-with-cron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!