简体   繁体   English

如何停止(并重新启动)Rails 服务器?

[英]How to stop (and restart) the Rails Server?

I'm following the instructions here http://railsinstaller.org/mac to 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 终端 window 或新终端?

Press Ctrl+C Ctrl+C

When you start the server it mentions this in the startup text. 启动服务器时,它会在启动文本中提到这一点。

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用作恶魔会很有用

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. 我对@zane关于如何删除PID文件的评论的最初回答是,它的行为可能取决于Rails版本或OS类型。 However, it's also possible that the shell runs the second command ( rails server -d ) sooner than the kill can actually cause the previous running instance to stop. 但是,它也有可能是外壳运行第二个命令( rails server -d )比越早kill实际上可以导致先前的运行实例停止。

So alternatively, kill -9 cat tmp/pids/server.pid && rails server -d might be more robust; 因此,或者, kill -9 cat tmp/pids/server.pid && rails server -d可能更可靠; or you can specifically run the kill , wait for the tmp/pids folder to empty out, then restart your new server. 或者,您可以专门运行kill ,等待tmp/pids文件夹清空,然后重新启动新服务器。

如果这种方法不起作用,则还有另一种方法在Windows中特别有效:从Windows命令行终止localhost:3000进程

I had to restart the rails application on the production so I looked for an another answer. 我不得不重新启动生产中的rails应用程序,所以我寻找了另一个答案。 I have found it below: 我在下面找到了它:

http://wiki.ocssolutions.com/Restarting_a_Rails_Application_Using_Passenger http://wiki.ocssolutions.com/Restarting_a_Rails_Application_Using_Passenger

if you are not able to find the rails process to kill it might actually be not running. 如果您找不到杀死Rails的进程,则它可能实际上没有运行。 Delete the tmp folder and its sub-folders from where you are running the rails server and try again. 从运行Rails服务器的位置删除tmp文件夹及其子文件夹,然后重试。

I just reboot the server with我只是重新启动服务器

Ctrl + c

That worked for me这对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM