Question

I have had lots of trouble with deploying my rails 3.0.10 application to Ubuntu 10.04 server with Passenger, Capistrano, nginx and MySQL (and even more trouble with apache2). After downgrading rake to 0.8.7 it's finally working, but now Sunspot/Solr doesn't work in my development environment. The sunspot_solr server is running, and I am able to get the server's url, and connect to it via the browser. The url is the same as in sunspot.yml. I have no idea what I have done that can have caused the problem. I had the same problem with sunspot earlier (before I downgraded rake). Then it suddenly started working again. I don't know why... I have tried two versions of Sunspot (1.2.1 and 1.3.0). Both have been working earlier, but not anymore.

This is the error message I'm getting:

SocketError (getaddrinfo: Name or service not known):
app/models/resource.rb:128:in `text_search'
app/controllers/search_controller.rb:21:in `index'

Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (161.6ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (168.9ms)

The controller is a bit messy so I just include the relevant part:

@criterion = params[:criterion]
@sort_direction = params[:sort_direction]
if @criterion && @sort_direction
  session["sort_search"] = @criterion + "|" + @sort_direction 
elsif session["sort_search"]
  @criterion = session["sort_search"].split("|")[0]
  @sort_direction = session["sort_search"].split("|")[1]
else
  @criterion = "updated_at"
  @sort_direction = "desc"
 end
@search = Resource.text_search(session[:search_params] || "", current_user, @criterion, @sort_direction) 
@resources = @search.results

I have not changed anything in the controller since it was working.

My gemfile:

source 'http://rubygems.org'
gem 'rake'
gem 'rails', '3.0.10'
gem 'jquery-rails', '>= 1.0.12'
gem 'sqlite3'
gem 'ancestry'
gem 'carrierwave'
gem 'sunspot_rails', '>= 1.3' #'~> 1.2.1' #
gem 'authlogic'
gem 'will_paginate'
gem 'declarative_authorization'
group :production do
  gem 'mysql'
end
group :development do
  gem 'sunspot_solr'
end
gem 'capistrano'

My rakefile:

require File.expand_path('../config/application', __FILE__)
require 'rake'

Skolearkivet::Application.load_tasks
Was it helpful?

Solution

just a wild guess, any chance you are using localhost as the hostname? Try changing localhost to 127.0.0.1

OTHER TIPS

I added this line to the top of file app/controllers/search_controller.rb

require 'resolv-replace'

Or alternatively you can put it to initializers/requires.rb

I had a similar issue, which I worked around by editing the /etc/resolv.conf

before

nameserver 10.0.x.x
search example.com

after

#nameserver 10.0.x.x
nameserver 8.8.8.8
#search example.com

I've been having the same issue with rails and logstasher on OSX, couldn't figure out what was going on until I read this post. Thought I'd add this so that anyone else having the same kind of issue with logstasher can find something...

`=> Booting Unicorn
=> Rails 4.2.5 application starting in development on http://0.0.0.0:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/xx/Projects/xx/config/environments/development.rb:80:in 'getaddress': getaddrinfo: nodename nor servname provided, or not known (SocketError)`

Fix was to add my machine hostname to the list under /etc/hosts for 127.0.0.1

For me it was sufficient to remove the search line in my resolv.conf. My company inserted automatically it's own domain and my hostname was not a FQDN in my hosts file. This is a test environment obviously.

It could be that one of your third party service URLs is incorrect. For example, we had the wrong SMTP mail address. An exception within the app caused it to email the error to the admins and it failed with the error. Here's how you know when it's a bad address:

irb(main):009:0> Socket.gethostbyname("example.net")
SocketError: getaddrinfo: Name or service not known

I added this line

require 'resolv-replace'

to my controller file where the error was coming from and it worked for me. Hope it works for you too!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top