Rails Server Keeps Exiting (SocketError) - ruby-on-rails

Rails noob here. I'm trying to work through Michael Hartl's Ruby on Rails Tutorial, but every time I run rails server, it keeps Exiting and shows me a SocketError. I was able to run the server just fine this past weekend using wifi from a startup, so I'm guessing it has something to do with my internet connection/firewall? I also ran into the same problem with the server at the library this afternoon.
Any help is appreciated! Thanks in advance.
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-02-23 22:33:11] INFO WEBrick 1.3.1
[2015-02-23 22:33:11] INFO ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
Exiting
/Users/awo/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:232:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)

I had messed with my hosts file in the past, and removing and creating a new default one (with localhost included) seemed to do the trick . Got mine from here:
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
I'm thinking the path was screwed up or there were some ninja whitespaces lurking in my /private/etc/hosts file.

I had the same problem recently, which I resolved by adding 127.0.0.1 localhost record to the private/etc/hosts file

First you need to identify the port id of rails server so run below command that give list of PID which run on 3000 port
lsof -wni tcp:3000
the number in the PID column to kill the process:
kill -9 PID

Related

Rails server not responding

I started a simple rails server and set the root url to display an html page. It started on localhost:3000 but when I try to access it using my browser (Internet Explorer 8) it says page cannot be diaplyed. The console is not showing any error. It just says server running on localhost:3000
Console output
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-04-27 12:32:39] INFO WEBrick 1.3.1
[2016-04-27 12:32:39] INFO ruby 2.2.4 (2015-12-16) [i386-mingw32]
[2016-04-27 12:32:39] INFO WEBrick::HTTPServer#start: pid=5752 port=3000
The most probable problem of that you have firewall and it blocks the requests to server, additionally it could be happened that name localhost is redefined, so I'll propose a 3 steps to fix:
Drop your firewall or reset it to allow accessing to 127.0.0.1, that should be resolved as localhost;
Restart app as:
rails s -b 127.0.0.1
key -b tells your server to bind it on just IP: 127.0.0.1;
Enter url: http://127.0.0.1:3000

Michael Hatl's Rails Tutorial Chapter 2: Errno::ENOENT in UsersController#index when testing /users

When generating toy_app using scaffolding I can go to the root site using the local server, but when I try to go to the page /users I get the following error message: "Errno::ENOENT in UsersController#index"
The page should allow me to enter a new user.
When I try to restart the server and run rails server -b $IP -p $PORTI get the following:
sunny_dee#rails-tutorial:~/workspace/toy_app (master) $ rails server -b $IP -p $PORT
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-04-27 18:06:55] INFO WEBrick 1.3.1
[2015-04-27 18:06:55] INFO ruby 2.1.5 (2014-11-13) [x86_64-linux]
Exiting
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
I finally got it to work by restarting the workspace. I'm guessing that is what restarted the local server. I was trying Ctrl-C but it was not working.
The tutorial uses Cloud9 and since it's a cloud IDE closing/logging out did nothing but when I clicked on the button to the left of "Share" on the top right corner and the clicked on "Restart" the page ran correctly.
Hopefully my stupid question can help someone else as well. Thanks everyone that took the time to contribute :)
If you running this application in your local Linux system just use -
rails server
Then you can access your site using http://localhost:3000/
You can also specify which port to run on using this command -
rails s -p 3001 -P tmp/pids/server2.pid
Then you can access using 3001 port.
You are getting that error because your 8080 port is already in use by some other process.

Basic Routing issue with Rails

I made the basic blog demo from a rails tutorial in a book from 2007. I realized it's dated so I deleted the blog I made and began to redo it from a tutorial here: http://guides.rubyonrails.org/getting_started.html#creating-the-blog-application
I started from scratch and now I'm stuck on 4.3 on that link's instructions because when I type in http://localhost:3000/ I keep getting the default screen for Rails instead of "Hello, Rails!" like the tut says I should.
The instructions on 4.3 are to type in
rm public/index.html
And then access the routes.rb file to uncomment the root to: section so that it says
root :to => "welcome#index"
I continued on with the migration and all that but I still keep getting the default screen.
Then I typed
rails server -d
to see if that does the trick but nope. It just says this only ending with the 2nd =>:
blog ❯ rails server -d
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
If I just type
rails server
I get an error in terminal that says the following:
blog ❯ rails server
=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-05-28 17:42:34] INFO WEBrick 1.3.1
[2012-05-28 17:42:34] INFO ruby 1.9.3 (2012-02-16) [x86_64-darwin11.3.0]
[2012-05-28 17:42:34] WARN TCPServer Error: Address already in use - bind(2)
Exiting
/Users/Nick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /Users/Nick/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/utils.rb:85:in `new'
If anyone wants me to paste the rest of the error I'll go ahead and do that.
I'm not sure what to do from here to fix this.
Thanks for your help
TCPServer Error: Address already in use - bind(2)
One of two things is happening:
You already have a WEBrick server running elsewhere on port 3000. Kill it before starting a new one.
Some other process is listening on port 3000
The first time you did rails server -d, you started a backgrounded WEBrick service that is eating port 3000. Find the running process and kill it via:
ps aux | grep ruby
kill [PID from above]
Then restart your WEBrick with just rails server. At this point, having already removed the public/index.html, your route should be active and working.

Rails starting in dev, says server is http://0.0.0.0 [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why does Ruby on Rails use 0.0.0.0:3000 instead of localhost:3000?
I am starting my server locally and for some reason I am noticing this line there:
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
Is that normal? My /etc/hosts file:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 app.cmply.local
127.0.0.1 api.cmply.local
127.0.0.1 m.cmply.local
But I had just experimented with taking out the first line there. Could that have caused the problem? I put the first line back, but the server still says http://0.0.0.0
Any idea why that might be happening?
0.0.0.0 means that it's listening on all interfaces; in other words, anybody who knows your IP address can access your Rails application. This is normal.
Yes, that is the standard address for your application when running the rails server command,
when you run that in the terminal you'll see:
$ cd commandsapp
$ rails server
=> Booting WEBrick
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
the line:
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
is letting you know that your app will be viewable at said address in your browser.
check out the railsguides link I posted for more info.
http://guides.rubyonrails.org/command_line.html

Webrick Fails to Run as Daemon, no Error Message

Running Ubuntu Server 10.04 with Rails 2.3.4 and Webrick 1.3.1; our rails app runs fine when called via script/server -e production, but trying to test it as a daemon by calling it with the -d flag produces the following output:
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
Nothing is produced in the logs, and other Rails applications will run detached without issue.
I assume You are running the Webrick in port 3000
>>$ sudo netstat -anp | grep 3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 8822/ruby
>>$ sudo kill -9 8822
I don't mean to contradict your choosing Webrick as a production server and maybe there is something I'm missing about why you are choosing Webrick, but have you considered other alternatives? I'd wager you already know all of this, but Webrick is the provided ruby server, and it is also the slowest ruby server choice.
Some of the most popular production server choices are:
Passenger
Thin
Mongrel
Unicorn
Glassfish
Passenger is likely the most popular choice for production now due to its easy configuration, speed, and features.
If there is a specific use case for Webrick that makes it better than any of the other server choices, I'd love to know.
You can add patch to enable error log here: https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/core_ext/process/daemon.rb#L16
To
unless noclose
STDIN.reopen "/dev/null" # Free file descriptors and
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
STDERR.reopen '/tmp/rails_daemon_err.log', 'a'
end
Now when you start rails server with -d, the error log will append to /tmp/rails_daemon.log.

Resources