我正在尝试运行以下Sinatra应用程序并收到一条错误消息,告诉我无法启动服务器,因为端口已经在使用或因为我没有root权限.在启动Sinatra应用程序之前,我从未遇到过这个问题.几天前我更新了Mountain Lion以获取我的mac,并想知道这可能是导致问题的原因.我也使用RVM.任何人都可以提出建议......
require "sinatra"
class MyApp < Sinatra::Base
get '/' do
"Hello from MyApp"
end
end
== Sinatra/1.3.3 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop
/Users/me/.rvm/gems/ruby-1.9.2-p290@global/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
Run Code Online (Sandbox Code Playgroud)
更新:我仍然可以在我的机器上运行rails服务器,所以我认为问题是针对Sinatra的.此外,几天前,当我开始使用这个指导我明确设置端口的Rack Tutorial时,我能够运行Sinatra应用程序 .我想知道这是否会永久改变.
>> Rack::Handler::WEBrick.run my_rack_proc, :Port => 9876
[2011-10-24 11:32:21] INFO WEBrick 1.3.1
[2011-10-24 11:32:21] INFO ruby 1.9.2 (2011-07-09) [i386-mingw32]
[2011-10-24 11:32:21] INFO WEBrick::HTTPServer#start: pid=480 port=9876
Run Code Online (Sandbox Code Playgroud)
Tar*_*oys 14
注意:之前我有一个不同的答案.我已经用一个新的,更有针对性的答案取而代之,但是对于仍在寻找它的人来说,我将旧答案留在了最底层.
此错误是由于您上次运行服务器时关闭终端而未终止服务器.我相信这被称为"无头跑",就像一只头被切断的鸡.因此,即使没有人在观看,服务器仍在运行并占用称为端口9393的"空间".当您尝试启动新服务器时,已经有一个正在运行.这有点像停车位:因为那里已经有一辆车,所以你不能在同一个地方放一辆新车.
这是我如何重现错误.我启动了一个sinatra服务器,关闭终端而没有先杀死服务器,打开一个新的终端,并试图启动另一台服务器.
Taras-MacBook-Air:SurveyDBCGroupProject tlroys$ shotgun
== Shotgun/Thin on http://127.0.0.1:9393/
Thin web server (v1.6.1 codename Death Proof)
Maximum connections set to 1024
Listening on 127.0.0.1:9393, CTRL+C to stop
/Users/tlroys/.rvm/gems/ruby-1.9.3-p484/gems/eventmachine-1.0.3/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
#deleted stack trace
如果汽车停在您的位置,您会怎么做?您可以拨打拖车并告诉司机车牌号码,并告诉他们将车拖走.
要查找汽车的车牌号,请运行我在Stack Overflow上找到的以下命令集
ps aux | grep ruby
This finds the process id, aka the license plate number of the 'car' occupying the 'parking spot.' Note: the server occupying my 'spot' is in fact a server written using the programming language ruby: sort of like some cars are Chevorlets. I can tell the person finding out the license plate number to look for the chevrolet, and he will find the right car as long as there are no other cars around. Since this 'zombie server' is the only ruby process running on my computer, telling the grep command to look for ruby will give the right process id/ license plate numbers. If I wanted to be more specific, I could probably say
ps aux | grep shotgun
and get the same result.
-The output should look like this: there should be two things in the list
27235 ?? S 0:00.72 /Users/tlroys/.rvm/gems/ruby-1.9.3-p484/bin/shotgun
27393 s000 S+ 0:00.00 grep ruby
The first one is the actual 'zombie server' you are looking for. The second thing is funny, because you are looking for all processes that contains the word ruby, and so it find the process that is looking for all processes that contain the word ruby. Haha.
Kill the first process. with the following command. Make sure to change the numbers to the actual process id:
kill -9 27235
You'll have to change the 27235 to the actual process id that you see, but you get the idea. The tow truck has come, dragged the car away to the junkyard, and left the spot free for me to use.
我有完全相同的问题,据我所知,这是因为我在运行我的sinatra应用程序的端口上运行了一个ruby进程.下面是错误(为了简洁起见,删除了堆栈跟踪)以及我运行的命令,以找出出错的原因并修复它.
简而言之,我试图启动我的sinatra应用程序,它说端口正在使用或需要root权限.然后我使用了Tin Man的lsof命令(如上所示)来找出正在使用的端口.
它显示红宝石在9393上运行.我用killall杀了它.我再次尝试启动我的sinatra应用程序.有效.
Taras-MacBook-Air:sinatra_sandbox tlroys$ bundle exec shotgun config.ru
The source :rubygems is deprecated because HTTP requests are insecure.
Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
== Shotgun/Thin on http://127.0.0.1:9393/
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 127.0.0.1:9393, CTRL+C to stop
/Users/tlroys/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
Taras-MacBook-Air:sinatra_sandbox tlroys$ lsof -i TCP | grep LISTEN
ruby 59176 tlroys 9u IPv4 0xffffff8012fbdc00 0t0 TCP localhost:9393 (LISTEN)
Taras-MacBook-Air:sinatra_sandbox tlroys$ killall ruby
Taras-MacBook-Air:sinatra_sandbox tlroys$ bundle exec shotgun config.ru
The source :rubygems is deprecated because HTTP requests are insecure.
Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
Shotgun/Thin on http://127.0.0.1:9393/
Thin web server (v1.5.0 codename Knife)
Maximum connections set to 1024
Listening on 127.0.0.1:9393, CTRL+C to stop
Run Code Online (Sandbox Code Playgroud)
关于只有 root 能够打开“众所周知的端口”的限制与 Ruby 无关 - 这是操作系统的事情。总的来说,这也是一件好事。
查看“无法启动 sinatra 进程 - eventmachine '无接受器' ”。
链接中有两个建议:
| 归档时间: |
|
| 查看次数: |
10649 次 |
| 最近记录: |