Node.js 如何在ubuntu的crontab中每4小时执行一次我的命令(永久模块nodejs)?

Node.js 如何在ubuntu的crontab中每4小时执行一次我的命令(永久模块nodejs)?,node.js,linux,cron,forever,Node.js,Linux,Cron,Forever,我首先执行下面的命令 crontab -u user_name -e # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for this pa

我首先执行下面的命令

crontab -u user_name -e

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for this particular task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
将显示上面的文件。 我已经将我的命令添加到上面文件的下一行

0 */4 * * * forever restart /var/www/html/app.js
但是上面的命令没有执行。 my app.js文件的文件路径为“/var/www/html/”。
我真正需要的是我在nodejs中的web服务在启动8小时后频繁停机(这不是数据库问题,因为我的数据库没有空闲)因此,我宁愿在开始使用crontab后每4小时重新启动一次。阅读您是否尝试使用
/usr/local/bin/forever
而不是“forever”?

首先通过在终端中键入echo$PATH检查路径是否设置,如果路径未设置,则将路径设置为 结果

echo $PATH
PATH=(上述命令的结果) 之后,您可以使用此命令运行cron

5 * * * * cd /path/to/your/project/ folder && /usr/local/bin/forever startall > /tmp/file.txt

> /tmp/file.txt
是检查cron是否正常工作。如果正常工作,您将在临时文件夹中以.txt文件作为日志