Ruby-on-rails 无法停止 Rails 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15088163/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:28:55  来源:igfitidea点击:

Can't stop rails server

ruby-on-rails

提问by epsilones

I am new to rails and I am using an ubuntu machine and the rubymine IDE. The problem is that I am unable to stop the rails server. I tried to stop the server by killing the rails process. But, when I run pgrep -l rails, no such process is found. So, I am only able to kill ruby processes, but, the server won't stop.

我是 Rails 的新手,我正在使用 ubuntu 机器和 ruby​​mine IDE。问题是我无法停止 Rails 服务器。我试图通过杀死 rails 进程来停止服务器。但是,当我运行时pgrep -l rails,没有找到这样的进程。所以,我只能杀死 ruby​​ 进程,但是,服务器不会停止。

I tried ./script/server stop(since I started it by running ./script/server start), but, that didn't work. Googling around and finding some stackoverflow posts, I tried to change the localhost port's listening port but without success. Could someone help?

我尝试过./script/server stop(因为我是通过运行启动它的./script/server start),但是,那没有用。谷歌搜索并找到一些stackoverflow帖子,我尝试更改本地主机端口的侦听端口但没有成功。有人可以帮忙吗?

回答by Learner

You can use other ports like the following:

您可以使用其他端口,如下所示:

rails server -p 3001

Normally in your terminal you can try Ctrl + Cto shutdown the server.

通常在您的终端中,您可以尝试Ctrl + C关闭服务器。

The other way to kill the Ruby on Rails default server (which is WEBrick) is:

杀死 Ruby on Rails 默认服务器(即WEBrick)的另一种方法是:

kill -INT $(cat tmp/pids/server.pid)

In your terminal to find out the PID of the process:

在你的终端中找出进程的PID:

$ lsof -wni tcp:3000

Then, use the number in the PID column to kill the process:

然后,使用 PID 列中的数字来终止进程:

For example:

例如:

$ kill -9 PID

And some of the other answers i found is:

我发现的其他一些答案是:

To stop the rails server while it's running, press:

要在运行时停止 rails 服务器,请按:

CTRL-C
CTRL-Z

You will get control back to bash. Then type (without the $):

您将重新获得控制权bash。然后输入(不带$):

$ fg

And this will go back into the process, and then quit out of Rails sproperly.

这将返回到进程中,然后退出Rails s正常。

It's a little annoying, but this sure beats killing the process manually. It's not too bad and it's the best I could figure out.

这有点烦人,但这肯定胜过手动终止进程。这还不错,这是我能想到的最好的。

Updated answer:

更新的答案:

You can use killall -9 railsto kill all running apps with "rails" in the name.

您可以使用“killall -9 rails杀死rails”名称中的所有正在运行的应用程序。

killall -9 rails

killall -9 rails

回答by maximus ツ

you can use grep command in following way,

您可以通过以下方式使用 grep 命令,

ps aux | grep rails

and then

进而

kill -9 {process_id} 

回答by Vasu Adari

pkill -9 railsto kill all the process of rails

pkill -9 rails杀死rails的所有进程

Updated answer

更新答案

ps aux|grep 'rails'|grep -v 'grep'|awk '{ print $2 }'|xargs kill -9

ps aux|grep 'rails'|grep -v 'grep'|awk '{ print $2 }'|xargs kill -9

This will kill any running rails process. Replace 'rails' with something else to kill any other processes.

这将杀死任何正在运行的 rails 进程。用其他东西替换“rails”以杀死任何其他进程。

回答by puneet18

Following are steps to kill server process:

以下是杀死服务器进程的步骤:

1. lsof -i tcp:3000

1. lsof -i tcp:3000

2. kill -9 1234

2. kill -9 1234

where 1234is the PID of process: localhost:3000 display in step 1.

1234进程的PID在哪里: localhost:3000 在步骤1中显示。

OR

或者

Remove file(server.pid) under Rails.root/tmp/pids/and restart server.

删除文件(server.pid)Rails.root/tmp/pids/并重新启动服务器。

OR

或者

open app in another port by using command:

使用命令在另一个端口打开应用程序:

rails s -p 3001

rails s -p 3001

回答by user2055780

On my MAC the killall -9 railsdoes not work. But killall -9 rubydoes.

在我的 MACkillall -9 rails上不起作用。但killall -9 ruby确实如此。

回答by przbadu

I generally use:

我一般使用:

killall ruby

killall ruby

OR

或者

pkill -9 ruby

pkill -9 ruby

which will kill all ruby related processes that are running like rails server, rails console, etc.

这将杀死所有正在运行像所有的红宝石相关的流程rails serverrails console

回答by Aravin

1. Simply Delete the pid file from rails app directory

1. 简单地从 rails app 目录中删除 pid 文件

Rails_app -> tmp -> pids -> pid file

Rails_app -> tmp -> pids -> pid file

Delete the file and run

删除文件并运行

rails start

rails start



2. For Rails 5.0 and above, you can use this command

2.对于Rails 5.0及以上,可以使用这个命令

rails restart

rails restart

回答by errakeshpd

Step 1:find what are the items are consuming 3000 port.

Step 1:找出哪些物品正在消耗3000端口。

lsof -i:3000

step 2 :Find the process named

第 2 步:找到名为的进程

For Mac

对于 Mac

ruby      TCP localhost:hbci (LISTEN)

For Ubuntu

对于 Ubuntu

ruby      TCP *:3000 (LISTEN)

Step 3:Find the PID of the process and kill it.

步骤3:找到进程的PID并杀死它。

kill -9 PID

回答by Santanu

Delete the server.pid from tmp/pids folder. In my case, the error was: A server is already running. Check /home/sbhatta/myapp/tmp/pids/server.pid.

从 tmp/pids 文件夹中删除 server.pid。就我而言,错误是:服务器已在运行。检查 /home/sbhatta/myapp/tmp/pids/server.pid。

So, I delete server.pid

所以,我删除了 server.pid

rm /home/sbhatta/myapp/tmp/pids/server.pidthen run rails s

rm /home/sbhatta/myapp/tmp/pids/server.pid然后运行 rails s

回答by Gopal S Rathore

Use ctrl+cto shutdown your Webrick Server.

使用ctrl+c关机您的WEBrick服务器。

Unfortunately if its not works then forcefully close the terminal and restart it.

不幸的是,如果它不起作用,则强行关闭终端并重新启动它。

Another trick is that

另一个技巧是

1. open your system-monitor(a gui application) on ubuntu

2. Select processes tab 

3. Then look for a process having name 'ruby'

4. End that process