首页 > 解决方案 > 永远运行几个脚本

问题描述

我在一个目录中有几个脚本,每个脚本都称为 bot 和它的编号,从 1 到脚本的编号。

我想做的是以某种方式通过终端通过 1 个命令行运行所有脚本(使用 Ubuntu),我使用forever命令来运行脚本而不停止等等。

你可以通过终端或使用节点 js 脚本来实现吗?

有没有像永远这样的其他命令可以为我做这件事?

标签: node.jsubuntuforever

解决方案


您可以通过带有 command 的命令行使用它forever

您需要JSON使用所需文件创建一个文件。

例子:

[
  {
    // App1
    "uid": "app1", // ID of the script.
    "append": true,
    "watch": true,
    "script": "bot1.js", // Name of the script
    "sourceDir": "" // Where the script is located. If it's in the
                    // same location as the json file, leave it ""
  },
  {
    // App2 = > Same as app1, just different script name.
    "uid": "app2",
    "append": true,
    "watch": true,
    "script": "bot2.js",
    "sourceDir": ""
  }
]

然后你只需要通过命令运行JSON文件。forever例子:

forever start apps.json

forever 您可以在此处查看更多信息。


推荐阅读