NodeJS Forever 封装 minUptime 和 spinSleepTime 警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24921154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NodeJS Forever package minUptime and spinSleepTime warnings
提问by John
I'm trying to run the forever function for node.js but I get below warnings;
我正在尝试为 node.js 运行永久函数,但我收到以下警告;
C:\serv>forever start SERVER.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up f
or at least 1000ms
info: Forever processing file: SERVER.js
How to set --minUptimeand --spinSleepTimeto remove these warnings
如何设置--minUptime和--spinSleepTime删除这些警告
Installed foreverpackage with npm install forever -g
安装forever包npm install forever -g
回答by Kh?i
These are only warnings. You could go on ignoring them, if you want.
But if you want to explicitly set them, forever --helptells you how to do so. Just start foreverwith:
这些只是警告。如果你愿意,你可以继续忽略它们。但是如果你想明确地设置它们,forever --help告诉你如何这样做。刚开始forever:
forever start --minUptime 1000 --spinSleepTime 1000 SERVER.js
回答by Dimitri De Franciscis
The documentation is not very exhaustive, a bit of additional information.
文档不是很详尽,有一些额外的信息。
In the following examples we will use two scripts:
在以下示例中,我们将使用两个脚本:
fail-fast.js:
失败fast.js:
process.exit(1);
fail-slow.js:
失败-slow.js:
setTimeout(() => { process.exit(1); }, 2000);
1) using defaults
1) 使用默认值
forever fail-fast.js
fail-fast.jsscript will execute only once, then no other start attempts will be made.
fail-fast.js脚本将只执行一次,然后不会进行其他启动尝试。
forever fail-slow.js
fail-slow.jsscript will be restarted indefinitely, as it stays up more than 1000ms (default value of minUptimeif not specified). You can limit the number of restarts with the -mparameter.
fail-slow.js脚本将无限期地重新启动,因为它会停留超过 1000 毫秒(minUptime如果未指定,则为默认值)。您可以使用-m参数限制重新启动的次数。
2) setting only minUptime
2) 仅设置 minUptime
forever --minUptime 10000 fail-fast.js
forever --minUptime 10000 fail-slow.js
Both fail-fast.jsand fail-slow.jswill be never be restarted, because we extended minUptimeto 10 seconds and now fail-slow.jsis considered spinning.
无论fail-fast.js和fail-slow.js将永远不会被重新启动,因为我们延长minUptime为10秒,现在fail-slow.js被认为是纺纱。
3) setting spinSleepTime
3) 设置 spinSleepTime
Whenever you set spinSleepTime(with or without minUptime), your process will restart even if it is considered 'spinning'.
无论何时设置spinSleepTime(有或没有minUptime),您的进程都会重新启动,即使它被认为是 'spinning'。
forever --spinSleepTime 30000 fail-fast.js
forever --spinSleepTime 30000 fail-slow.js
Both scripts will be restarted forever, waiting spinSleepTimemilliseconds between restarts.
这两个脚本将永远重新启动,spinSleepTime在重新启动之间等待几毫秒。
回答by user6590090
In short:
简而言之:
When stop
if hadRunTime >= minUptime
restart
else if spinSleepTime != 0
wait spinSleepTime
restart
else
stop and no restart
@Megadix The answer has something wrong with spinSleepTime.
fail-fast.jswill restart wating spinSleepTime,but fail-slow.jswill restart immediately,no waiting! It can be Proved by:
@Megadix 答案有问题spinSleepTime。
fail-fast.js将重新启动spinSleepTime,但fail-slow.js会立即重新启动,无需等待!可以通过以下方式证明:
console.log((new Date()).getTime());
setTimeout(() => {
process.exit(1);
}, 2000);
output like:
输出如:
1468812185697
error: Forever detected script exited with code: 1
error: Script restart attempt #1
1468812187766
error: Forever detected script exited with code: 1
error: Script restart attempt #2
1468812189834
error: Forever detected script exited with code: 1
error: Script restart attempt #3
1468812191901
error: Forever detected script exited with code: 1
error: Script restart attempt #4
1468812193977
error: Forever detected script exited with code: 1
error: Script restart attempt #5
1468812196039
error: Forever detected script exited with code: 1
error: Script restart attempt #6
1468812198107
error: Forever detected script exited with code: 1
error: Script restart attempt #7
1468812200172
error: Forever detected script exited with code: 1
回答by jgillich
forever start --minUptime 1234 --spinSleepTime 3421 SERVER.js
回答by cyprian
I'm assuming you are using express module that is way after you using - forever start SERVER.js - your server is not running, because express module run server in path ./bin/www - so you should use this command - forever start ./bin/www --name="SERVER" - name is the name of your js file, by default app.js
我假设您使用的 Express 模块是在您使用之后的方式 - 永远启动 SERVER.js - 您的服务器没有运行,因为 express 模块在路径 ./bin/www 中运行服务器 - 所以你应该使用这个命令 - 永远启动./bin/www --name="SERVER" - name 是你的 js 文件名,默认是 app.js

