使用cron每12小时重新启动pm2应用程序 [英] Restart pm2 app every 12h with cron
问题描述
尝试过此方法,但不起作用:
Tried this, but it doesn't work:
SHELL=/bin/bash
PATH=/usr/lib/node_modules/pm2/bin
* 0,12 * * * pm2 restart all
我在做什么错了?
推荐答案
使用crontab -e
编辑cron并添加以下内容:
Edit cron with crontab -e
and add the following:
0 */12 * * * /usr/bin/node /usr/bin/pm2 restart all
对于计划,请每12小时使用一次0 */12 * * *
,或者分别对于0:00和12:00使用0 0,12 * * *
. (您的时间表* 0,12 * * *
会在第0小时和第12小时,0:00、0:01、0:02 ...的每一分钟触发一次)
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...)
对于该命令,如fedorqui所述,请使用节点的路径,然后使用pm2和pm2选项的路径.使用which node
和which pm2
获取节点和pm2的路径.
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.
这篇关于使用cron每12小时重新启动pm2应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!