运行 Ubuntu 环境中一天中特定时间的节点服务器?

Running a node server at certain times of day in an Ubuntu environment?

我 运行 在 Ubuntu 服务器上安装我的小型节点应用程序,我可以使用简单的 Upstart 脚本在服务器启动时自动启动节点服务器。

但是,我希望节点应用程序在一天中的特定时间 运行 - 我有哪些实施方案? 最好是在 Node 应用程序中还是在 Ubuntu 环境中执行此操作?

cron呢?

$ crontab -e

# in the editor that opens:
0 */2 * * * ~/path/to/your/node/script.js > /tmp/out.log 2> /tmp/err.log

这将每 2 小时 运行 您的 script.js,即 0:00(午夜)、2:00、4:00 等。它还会登录到您的 /tmp 目录,但这完全是可选的。