我正在尝试通过IIS10上的 PM2 在 Windows Server 2016 上使用 Node.js 版本 12.14.0 运行 Docusaurus。我正在使用 PM2,因此我可以在服务器重新启动后重新启动应用程序。我现在不得不承认,今天是我第一次尝试使用 Node.js,所以请多多包涵。
这通常npm run start
通过在 Docusaurus 目录中调用来运行。在测试 Node.js 以及“Hello World”应用程序是否会在服务器重新启动时启动时,我使用的ecosystem.config.js
是 PM2 文档中建议的方法。这称为像这样的javascript文件。
module.exports = {
apps: [
{
name: "HelloWorld",
script: "apps\\hello_world.js",
instances: 1
}
]
}
这工作得很好,但我找不到任何关于如何npm start
从这个文件运行的文档(尽管我确实尝试调用一个单独的批处理文件,但这也不起作用)。然后我在这里看到我可以调用一个记录更多选项的 JSON 文件。
JSON配置文件:
{
"apps": [
{
"name": "docs",
"cwd": "apps\\docs",
"script": "npm",
"args": "start"
},
{
"name": "HelloWorld",
"script": "apps\\hello_world.js"
}
]
}
“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"
这让我在 GitHub 上遇到了这个问题。不过,在这些问题上似乎没有很多活动,而且也有过历史性的事件。
我认为我可能在 PM2 上做错了什么,或者它有问题,因为我也无法通过命令行使用 PM2 启动文档。
C:\Node JS\apps\docs>pm2 start npm --name "docs" -- start
有没有人对我如何让它工作有任何想法或尝试做类似的事情?我会接受以下答案:
- 在 Windows Server 上运行 Docusaurus 的另一种方法。
- 使用 PM2 的替代方法。
- 任何其他想法。
抱歉,如果我漫无目的。
编辑:
的输出pm2 start ecosystem.json --only docs
C:\Node JS>pm2 start ecosystem.json --only docs
[PM2][WARN] Applications docs not running, starting...
[PM2][ERROR] Process failed to launch EPERM: operation not permitted, open 'C:\etc\.pm2\logs\docs-out.log'
它引用的日志是空的。docs-error.log
重复相同的错误,但自昨晚以来一直没有更新。它可能是由我在 JSON 文件中尝试不同的语法创建的,但无论如何都会发布它。
SyntaxError: Unexpected token ':'
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Object.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:27:21)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
:: Created by npm, please don't edit manually.