Ruby on Rails mac问题服务器已经运行

时间:2015-07-24 14:56:13

标签: ruby-on-rails macos server

我正在尝试开始学习Ruby on Rails,我在让服务器正确启动或停止时遇到问题,我不确定原因。

据我所知,当我启动服务器时,它会一直运行,直到我按Ctrl + C将其关闭。

然而,如果我运行bin / rails服务器启动它,它说已经有一个服务器在端口3000运行,所以我需要使用一个不同的端口,我在下面做了。我不想每次都继续制作新的端口。

我做错了什么人?

Gavins-MacBook-Pro:buro MacBook$ bin/rails server -p 3001
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3001
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
A server is already running. Check /Users/MacBook/buro/tmp/pids/server.pid.
Exiting
Gavins-MacBook-Pro:buro MacBook$ 
Gavins-MacBook-Pro:buro MacBook$ bin/rails server -p 3001
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3001
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
A server is already running. Check /Users/MacBook/buro/tmp/pids/server.pid.
Exiting
Gavins-MacBook-Pro:buro MacBook$ bin/rails server -p 3002
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3002
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
A server is already running. Check /Users/MacBook/buro/tmp/pids/server.pid.
Exiting
Gavins-MacBook-Pro:buro MacBook$ 

此外,我尝试删除pid文件,但后来我仍然得到这个:

Gavins-MacBook-Pro:buro MacBook$ bin/rails server
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-07-24 10:58:14] INFO  WEBrick 1.3.1
[2015-07-24 10:58:14] INFO  ruby 2.2.2 (2015-04-13) [x86_64-darwin14]
Exiting
/Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/socket.rb:206:in `bind': Address already in use - bind(2) for 127.0.0.1:3000 (Errno::EADDRINUSE)
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/socket.rb:206:in `listen'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/socket.rb:461:in `block in tcp_server_sockets'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/socket.rb:232:in `each'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/socket.rb:232:in `foreach'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/socket.rb:459:in `tcp_server_sockets'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/utils.rb:70:in `create_listeners'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/server.rb:133:in `listen'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/server.rb:114:in `initialize'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:45:in `initialize'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:31:in `new'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:31:in `run'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/server.rb:80:in `start'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/MacBook/buro/bin/rails:8:in `require'
    from /Users/MacBook/buro/bin/rails:8:in `<top (required)>'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/client/rails.rb:28:in `load'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/client/rails.rb:28:in `call'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/client/command.rb:7:in `call'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/client.rb:26:in `run'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.6/bin/spring:48:in `<top (required)>'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/binstub.rb:11:in `load'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.3.6/lib/spring/binstub.rb:11:in `<top (required)>'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/MacBook/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/MacBook/buro/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

1 个答案:

答案 0 :(得分:1)

ps ax | grep server

并寻找您的rails服务器。每个结果行中的第一个数字是进程ID,也就是&#34; pid&#34;。你可以杀死这些过程,如

kill -9 12345

其中12345是一个示例pid。

杀死所有人然后再做

rm tmp/pids/server.pid

好的措施。顺便说一下,这些都是在终端中在您的应用程序的根文件夹(从中运行服务器)中完成的。