Ruby-on-rails 服务器已经在 Rails 中运行

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

Server is already running in Rails

ruby-on-railsruby-on-rails-3.2command-promptwebrick

提问by swapnesh

When I am starting rails server using rails scommand it is showing A server is already running. Check C:/Sites/folder/Pids/Server.pids

当我使用rails s命令启动 rails 服务器时,它显示A server is already running. Check C:/Sites/folder/Pids/Server.pids

When I open the file it is outputting a 4 digit number only so how could I resolve this issue ?

当我打开文件时,它只输出一个 4 位数字,我该如何解决这个问题?

FYI

供参考

  1. No other instance of Rails cmd is running this time.
  2. Checked Task manager but only cmd.exeis showing no else process is running. (using Windows).
  1. 这次没有其他 Rails cmd 实例正在运行。
  2. 检查任务管理器,但只cmd.exe显示没有其他进程正在运行。(使用 Windows)。

回答by rainkinz

Remove the file: C:/Sites/folder/Pids/Server.pids

删除文件:C:/Sites/folder/Pids/Server.pids

ExplanationIn UNIX land at least we usually track the process id (pid) in a file like server.pid. I think this is doing the same thing here. That file was probably left over from a crash.

解释至少在 UNIX 领域,我们通常在 server.pid 之类的文件中跟踪进程 ID (pid)。我认为这在这里做同样的事情。该文件可能是崩溃后遗留下来的。

回答by Taimoor Changaiz

TL;DR Just Run this command to Kill it

TL;DR 只需运行此命令即可杀死它

sudo kill -9 $(lsof -i :3000 -t)

Root Cause:Because PID is locked in a file and web server thinks that if that file exists then it means it is already running. Normally when a web server is closed that file is deleted, but in some cases, proper deletion doesn't happen so you have to remove the file manually New Solutions

根本原因:因为 PID 被锁定在一个文件中,并且 Web 服务器认为如果该文件存在则意味着它已经在运行。通常,当 Web 服务器关闭时,该文件会被删除,但在某些情况下,不会发生正确的删除,因此您必须手动删除该文件 新解决方案

when you run rails s

当你运行rails s

=> Booting WEBrick

=> 启动 WEBrick

=> Rails 4.0.4 application starting in development on http://0.0.0.0:3000

=> Rails 4.0.4 应用程序开始开发 http://0.0.0.0:3000

=> Run rails server -hfor more startup options

=> 运行rails server -h以获得更多启动选项

=> Ctrl-C to shutdown server

=> Ctrl-C 关闭服务器

A server is already running. Check /your_project_path/tmp/pids/server.pid.Exiting

服务器已经在运行。检查 /your_project_path/tmp/pids/server.pid。退出

So place your path shown here /your_project_path/tmp/pids/server.pid

所以把你的路径显示在这里 /your_project_path/tmp/pids/server.pid

and remove this server.pidfile:

并删除此server.pid文件:

rm /your_project_path/tmp/pids/server.pid

OR Incase you're server was detached then follow below guidelines:

或者,如果您的服务器已分离,请遵循以下准则:

If you detached you rails server by using command "rails -d" then,

如果您使用命令“rails -d”分离了 rails 服务器,则

Remove rails detached server by using command

使用命令删除 rails 分离的服务器

ps -aef | grep rails

OR by this command

或者通过这个命令

sudo lsof -wni tcp:3000

then

然后

kill -9 pID

OR use this command

或使用此命令

To find and kill process by port name on which that program is running. For 3000 replace port on which your program is running.

按运行该程序的端口名称查找并终止进程。对于 3000 替换运行程序的端口。

sudo kill -9 $(lsof -i :3000 -t)

Old Solution:

旧解决方案:

rails s -p 4000 -P tmp/pids/server2.pid

Also you can find this post for more options Rails Update to 3.2.11 breaks running multiple servers

您也可以在这篇文章中找到更多选项 Rails Update to 3.2.11 break running multiple servers

回答by Josh Bedo

lsof -wni tcp:3000

Then you should see the ruby process and you can run

然后你应该看到ruby进程,你可以运行

kill -9 processid

you should be good to run the process now

你现在应该很好地运行这个过程

rails s thin

running multiple processes doesn't seem like a good idea and from what i've read many people agree. I've noticed many memory leaks with rails unfortunately so I couldn't imagine having two processes running. I know with one overtime my page refreshes increasingly become slower because of the data being stored on memory.

运行多个进程似乎不是一个好主意,从我读到的很多人都同意。不幸的是,我注意到 Rails 有很多内存泄漏,所以我无法想象有两个进程在运行。我知道,由于数据存储在内存中,我的页面刷新会随着超时而变得越来越慢。

回答by Karan Purohit

kill -9 $(lsof -i tcp:3000 -t)

回答by manu

You can get rid of the process by killing it:

您可以通过杀死它来摆脱该进程:

kill -9 $(lsof -i tcp:3000 -t)

回答by user1251378

$ lsof -wni tcp:3000

# Kill the running process
$ kill -9 5946

$ rm tmp/server.pids

foreman start etc start the service

foreman start etc 启动服务

回答by Lorenzo Sinisi

gem install shutup

gem install shutup

then go in the current folder of your rails project and run

然后进入 Rails 项目的当前文件夹并运行

shutup# this will kill the Rails process currently running

shutup# 这将杀死当前正在运行的 Rails 进程

You can use the command 'shutup' every time you want

您可以随时使用命令“shutup”

DICLAIMER: I am the creator of this gem

DICLAIMER:我是这颗宝石的创造者

NOTE: if you are using rvm install the gem globally

注意:如果您使用 rvm,请全局安装 gem

rvm @global do gem install shutup

回答by Ashish Sharma

It happens when you kill your server process and the pid file was not updated. The best solution is to delete the file Server.pid.

当您终止服务器进程并且 pid 文件未更新时,就会发生这种情况。最好的解决方案是删除文件Server.pid

Use the command

使用命令

rm <path to file Server.pid>

rm <path to file Server.pid>

回答by Cherenkov

Probably you suspended the server by: ^Z.

也许你被暂停服务器:^Z

The four digital number that vim C:/Sites/folder/Pids/Server.pidsoutputs is the process id.

vim C:/Sites/folder/Pids/Server.pids输出的四位数字是进程ID。

You should kill -9 processid, replacing the process id with the 4 numbers that vim (or other editor) outputed.

您应该kill -9 processid将进程 ID 替换为 vim(或其他编辑器)输出的 4 个数字。

回答by almawhoob

Run:fuser -k -n tcp 3000

跑:fuser -k -n tcp 3000

This will kill the process running at the default port 3000.

这将终止在默认端口 3000 上运行的进程。