通过永远为 nodejs 自动重启服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8951297/
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
automatically restarting service via forever for nodejs
提问by coure2011
I found that forever can run nodejs server forever. Is forever supports this feautre?
我发现永远可以永远运行 nodejs 服务器。是永远支持这个功能吗?
-- If the nodejs script is modified changed, the server shld restarted automatically.
How can I enable this feature using forever? or I need something else?
如何永久启用此功能?或者我需要别的东西?
采纳答案by Vinoth Gopi
回答by fent
From the forever readme. Use the -wflag to watch file for changes.
来自永远的自述文件。使用该-w标志来监视文件的更改。
回答by CrimsonKissaki
In case someone else, like myself, comes to find this through google.
以防其他人,比如我自己,通过谷歌找到这个。
I have to run it thusly:
我必须这样运行它:
forever --watch ./start/file
For me, at least, it defaults to watching the current directory I'm running the command in for changes. ./start/file is the file that "npm start" hits up from your package.json.
至少对我来说,它默认查看我正在运行命令以进行更改的当前目录。./start/file 是“npm start”从你的 package.json 中找到的文件。
If you need to watch a different directory from where you're pwd shows you to be, try:
如果您需要观看与密码显示位置不同的目录,请尝试:
forever --watch --watchDirectory ./path/to/dir ./start/file
For some reason "forever start xxxxxxxxx" only brings up the help information for me, but this works. /me shrugs.
出于某种原因,“永远启动 xxxxxxxxx”只会为我提供帮助信息,但这有效。/我耸了耸肩。
回答by mikgan
Again just another example of its usage (and it does work :D)
再次只是它用法的另一个例子(它确实有效:D)
forever -w --watchDirectory . --watchIgnore *.log -o ./log/out.log -e ./log/err.log index.js
That will launch the app in the same process with output to stdout/stderr (but also written to the logs)
这将在同一进程中启动应用程序并输出到 stdout/stderr(但也会写入日志)
To launch it in prod watching is obviously not a good idea and running it as a deamon is probably what you are after so drop the -w flags and add the "start" command
在 prod watch 中启动它显然不是一个好主意,将它作为守护进程运行可能是你所追求的,所以删除 -w 标志并添加“start”命令
forever -o ./log/out.log -e ./log/err.log start index.js

