Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails-tutorial Chapter 1: rails server isn't working on Cloud9

https://www.railstutorial.org/book/beginning#sec-rails_server

I have reached this step, and I'm using the cloud9 environment. When I run the server as per Listing 1.7 on that tutorial, however, I get this error:

myname@rails-tutorial:~/workspace/hello_app $ rails server -p $PORT -b $IP
=> Booting WEBrick
=> Rails 4.2.0.beta2 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-10-30 21:44:22] INFO  WEBrick 1.3.1
[2014-10-30 21:44:22] INFO  ruby 2.1.1 (2014-02-24) [x86_64-linux]
Exiting /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `listen'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `each'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:232:in `foreach'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:459:in `tcp_server_sockets'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/utils.rb:75:in `create_listeners'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:132:in `listen'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:113:in `initialize'
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:45:in `initialize'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `new'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:32:in `run'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/rack-1.6.0.beta/lib/rack/server.rb:288:in `start'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/server.rb:80:in `start'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/railties-4.2.0.beta2/lib/rails/commands.rb:17:in `<top (required)>'
    from /home/ubuntu/workspace/hello_app/bin/rails:8:in `require'
    from /home/ubuntu/workspace/hello_app/bin/rails:8:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
    from /usr/local/rvm/gems/ruby-2.1.1@rails4/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
    from /home/ubuntu/workspace/hello_app/bin/spring:16:in `require'
    from /home/ubuntu/workspace/hello_app/bin/spring:16:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

I've tried specifying a different port, but that doesn't work and the cloud9 environment suggests to me I should just use the $PORT variable.

The error "Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)" implies that I already have a rails server running, but I don't. I'm not really sure what to do here and the tutorial doesn't suggest any method of troubleshooting this issue.

like image 377
Josh Burson Avatar asked Oct 30 '14 21:10

Josh Burson


3 Answers

I learned that you can use the command killall ruby to stop any of the ruby processes which helped me because I had mistakenly run the rails server -b $IP -p $PORT command at the ~/workspace level in the tutorial. I found the answer in can't open rails server

like image 130
Tommy Avatar answered Nov 09 '22 00:11

Tommy


I ended up starting the tutorial from scratch again and it worked fine, but anyone with this problem in the future may find this troubleshooting technique I received from cloud9's support team useful:


Try:

lsof -i:8080

This will give the app that occupies it.

If apache, stop it using:

sudo /etc/init.d/apache2 stop

Hope this answer is of use to anyone with this problem.

like image 37
Josh Burson Avatar answered Nov 08 '22 22:11

Josh Burson


Probably you just had the other server still running. The one you initiate earlier on in he tutorial with the rails server command. You need to shut the other one down first using Ctrl+C, then try rails server -b $IP -p $PORT again

like image 28
marfsco Avatar answered Nov 08 '22 23:11

marfsco