Ash*_*Ash 1 node.js npm pm2 docusaurus
我正在尝试通过 IIS10 上的 PM2 在 Windows Server 2016 上使用 Node.js 版本 12.14.0运行Docusaurus 。我正在使用 PM2,因此我可以在服务器重新启动后重新启动应用程序。我现在必须承认,今天是我第一次尝试使用 Node.js,所以请耐心等待。
这通常通过在 Docusaurus 目录中调用来运行。npm run start在测试 Node.js 以及“Hello World”应用程序是否会在服务器重新启动时启动时,我使用了ecosystem.config.jsPM2 文档中建议的方法。这称为一个 javascript 文件,如下所示。
module.exports = {
    apps: [
      {
        name: "HelloWorld",
        script: "apps\\hello_world.js",
        instances: 1
      }
    ]
  }
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我找不到任何有关如何npm start从该文件运行的文档(尽管我确实尝试调用单独的批处理文件,但这也不起作用)。然后我在这里看到我可以调用一个记录了更多选项的 JSON 文件。
JSON 配置文件:
{
    "apps": [
        {
            "name": "docs",
            "cwd": "apps\\docs",
            "script": "npm",
            "args": "start"
        },
        {
            "name": "HelloWorld",
            "script": "apps\\hello_world.js"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)
“HelloWorld”脚本启动,但文档应用程序不启动。
pm2 报告提供以下输出:
PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:22: PM2 log: Script C:\PROGRAM FILES\NODEJS\NPM.CMD had too many unstable restarts (16). Stopped. "errored"
Run Code Online (Sandbox Code Playgroud)
这让我在 GitHub 上看到了这个问题。不过,关于这些问题的活动似乎并不多,而且也有历史性的事件发生。
我认为 PM2 可能做错了什么或者它有问题,因为我也无法通过 PM2 的命令行启动文档。
{
    "apps": [
        {
            "name": "docs",
            "cwd": "apps\\docs",
            "script": "npm",
            "args": "start"
        },
        {
            "name": "HelloWorld",
            "script": "apps\\hello_world.js"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)
有没有人对我如何让它发挥作用有任何想法或尝试过做类似的事情?我愿意回答以下问题:
如果我胡言乱语,抱歉。
编辑:
输出pm2 start ecosystem.json --only docs
PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:20: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
PM2        | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-07T17:54:22: PM2 log: Script C:\PROGRAM FILES\NODEJS\NPM.CMD had too many unstable restarts (16). Stopped. "errored"
Run Code Online (Sandbox Code Playgroud)
它引用的日志是空的。多次重复docs-error.log同样的错误,但从昨晚开始就没有更新了。它可能是我在 JSON 文件中尝试不同的语法创建的,但还是发布了它。
C:\Node JS\apps\docs>pm2 start npm --name "docs" -- start
Run Code Online (Sandbox Code Playgroud)
    问题实际上是 pm2 如何通过 Windows 上的批处理文件调用节点。如果您npm-cli.js直接使用其完整路径调用,程序将正常运行。
{
    "apps": [
        {
            "name": "docs",
            "cwd": "some_path_to\\apps\\docs",
            "script": "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js",
            "args": "start",
            "exec_mode": "cluster",
            "instances": 1,
            "interpreter": "none"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           6120 次  |  
        
|   最近记录:  |