【发布时间】:2020-04-25 07:00:17
【问题描述】:
我正在尝试通过 IIS10 上的 PM2 在 Windows Server 2016 上使用 Node.js 版本 12.14.0 运行 Docusaurus。我正在使用 PM2,因此我可以在服务器重新启动后重新启动应用程序。我现在不得不承认,今天是我第一次尝试使用 Node.js,所以请多多包涵。
这是 usually run,在 Docusaurus 目录中调用 npm run start。在测试 Node.js 以及“Hello World”应用程序是否会在服务器重新启动时启动时,我使用了 PM2 文档中建议的ecosystem.config.js。这称为像这样的javascript文件。
module.exports = {
apps: [
{
name: "HelloWorld",
script: "apps\\hello_world.js",
instances: 1
}
]
}
这工作得很好,但是我找不到任何关于如何从这个文件运行npm start 的文档(尽管我确实尝试调用一个单独的批处理文件,但这也不起作用)。然后我看到here 我可以调用一个记录更多选项的 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 上的 this 问题。不过,关于这些问题的活动似乎并不多,而且历史上也有过此类事件。
我认为我在使用 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.
【问题讨论】:
-
pm2 start ecosystem.config.js --only docs的输出是什么? -
嗨瓦希德。根据要求添加了额外的输出。
-
如果不赞成投票的人评论他们为什么这样做会很好。直到昨天我才接触到这些技术,我认为这个问题表明了学习的意愿。
-
如果目标是Windows平台,则需要
run as administartor命令行。因为你的文件在C盘,而你当前的用户没有足够的权限。 -
嗨 Vahid,恐怕这是来自提升的管理员提示。
标签: node.js npm pm2 docusaurus