Ruby-on-rails 如何停止(并重新启动)Rails 服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13655792/
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
How to stop (and restart) the Rails Server?
提问by Paul Seattle
I'm following the instructions here http://railsinstaller.org/macto get up and running with Rails on a Mac running OS X 10.8.2
我正在按照http://railsinstaller.org/mac上的说明在运行 OS X 10.8.2 的 Mac 上启动并运行 Rails
At step 8 I'm asked to restart Rails server but how?
在第 8 步,我被要求重新启动 Rails 服务器,但如何重新启动?
I'm assuming via a command line, but from within the already open ruby terminal window or a new one?
我假设是通过命令行,但是在已经打开的 ruby 终端窗口中还是在一个新的终端窗口中?
回答by jefflunt
Press Ctrl+C
按 Ctrl+C
When you start the server it mentions this in the startup text.
当您启动服务器时,它会在启动文本中提到这一点。
回答by Daniel Antonio Nu?ez Carhuayo
Now in rails 5 yu can do:
现在在 rails 5 中可以做到:
rails restart
This print by rails --tasks
这印由 rails --tasks
Restart app by touching tmp/restart.txt
通过触摸 tmp/restart.txt 重新启动应用程序
I think that is usefully if you run rails as a demon
我认为如果你像恶魔一样运行 rails,那会很有用
回答by sameers
On OSX, you can take advantage of the UNIX-like command line - here's what I keep handy in my .bashrc to enable me to more easily restart a server that's running in background (-d) mode (note that you have to be in the Rails root directory when running this):
在 OSX 上,您可以利用类似 UNIX 的命令行 - 这是我在 .bashrc 中随身携带的内容,使我能够更轻松地重新启动在后台 (-d) 模式下运行的服务器(请注意,您必须处于运行时的 Rails 根目录):
alias restart_rails='kill -9 `cat tmp/pids/server.pid`; rails server -d'
My initial response to the comment by @zane about how the PID file isn't removed was that it might be behavior dependent on the Rails version or OS type. However, it's also possible that the shell runs the second command (rails server -d) sooner than the killcan actually cause the previous running instance to stop.
我对@zane 关于如何不删除 PID 文件的评论的最初回应是,它的行为可能取决于 Rails 版本或操作系统类型。但是,也有可能 shell 运行第二个命令 ( rails server -d) 的时间比kill实际导致前一个正在运行的实例停止的时间早。
So alternatively, kill -9 cat tmp/pids/server.pid && rails server -dmight be more robust; or you can specifically run the kill, wait for the tmp/pidsfolder to empty out, then restart your new server.
因此,或者,kill -9 cat tmp/pids/server.pid && rails server -d可能更健壮;或者您可以专门运行kill,等待tmp/pids文件夹清空,然后重新启动新服务器。
回答by lawrencesloan
In case that doesn't work there is another way that works especially well in Windows: Kill localhost:3000 process from Windows command line
如果这不起作用,还有另一种在 Windows 中特别有效的方法:Kill localhost:3000 process from Windows command line
回答by Nickolay Kondratenko
I had to restart the rails application on the production so I looked for an another answer. I have found it below:
我不得不重新启动生产中的 rails 应用程序,所以我寻找另一个答案。我在下面找到了它:
http://wiki.ocssolutions.com/Restarting_a_Rails_Application_Using_Passenger
http://wiki.ocssolutions.com/Restarting_a_Rails_Application_Using_Passenger
回答by Rohan
if you are not able to find the rails process to kill it might actually be not running. Delete the tmp folder and its sub-folders from where you are running the rails server and try again.
如果您无法找到要杀死的 rails 进程,它实际上可能没有运行。从运行 rails 服务器的位置删除 tmp 文件夹及其子文件夹,然后重试。

