Errno::ECONNREFUSED (Connection refused... in production environment

1.2k views Asked by At

I have finished my app and I am trying to check the production environment. The app uses sunspot_rails gem for search. It works fine on the development server but it does not work on the production environment. My production logs gives the following:

Errno::ECONNREFUSED (Connection refused -        {:data=>"fq=type%3AArticle&start=0&rows=1&q=%2A%3A%2A", :method=>:post, :params=>{:wt=>:ruby}, :query=>"wt=ruby", :headers=>{"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, :path=>"select", :uri=>#<URI::HTTP:0x007ff38e350578 URL:http://localhost:8983/solr/production/select?wt=ruby>, :open_timeout=>nil, :read_timeout=>nil, :retry_503=>nil, :retry_after_limit=>nil}):
app/controllers/articles_controller.rb:12:in `index'

How do I solve this issue ?

Here is my articles_controller:

    class ArticlesController < ApplicationController
  before_filter :require_login, except: [:show, :index]
 def index
  @search = Article.search do
  fulltext params[:search]
  paginate :page => params[:page], :per_page => 1
  end
    @articles = @search.results 
  #@articles_by_month = Article.find(:all).group_by { |post| post.created_at.strftime("%B") }
 end
def show
  @article = Article.find(params[:id])
  @comment = Comment.new
 @comment.article_id = @article.id
end
def new
 @article = Article.new
end
def create
 @article = Article.new(article_params)
 @article.save
 redirect_to article_path(@article)
end
def edit
 @article = Article.find(params[:id])
end
def destroy
 @article = Article.find(params[:id])
 @article.destroy
 redirect_to articles_path
end
def update
 @article = Article.find(params[:id])
 @article.update(article_params)
 flash.notice = "Article '#{@article.title}' Updated!"
 redirect_to article_path(@article)
end
def article_params
 params.require(:article).permit(:title, :body, :tag_list, :picture)
end
end

And here is my Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.8'
gem 'bcrypt','3.1.7'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sprockets', '2.11.0'
gem 'carrierwave',             '0.10.0'
gem 'mini_magick',             '3.8.0'
gem 'fog',                     '1.23.0'
gem 'sorcery'
gem 'will_paginate',           '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'sunspot_rails'
gem 'progress_bar'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
gem 'sunspot_solr'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.3'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end

How do I solve this issue ?

2

There are 2 answers

0
iMacTia On

Have you started the solr instance in your production server?

bundle exec sunspot-solr start -p 8983
0
Alex Tsankov On

I dealt with some similar issues with Solr in the past. I made a script to handle launching it for me. It makes sure any crufty files that may affect access are cleaned up.

Hope this helps out!

See below:

pkill -f solr

#remove old data
rm -rf solr/data
rm -rf solr/default
rm -rf solr/development
rm -rf solr/pids
rm -rf solr/test

while getopts 'pdt' flag; do
  case "${flag}" in
    d) export RAILS_ENV=development ;;
    p) export RAILS_ENV=production ;;
    t) export RAILS_ENV=test ;;
    *) error "Unexpected option ${flag}" ;;
  esac
done

#startup solr
bundle exec rake sunspot:solr:start

echo "Solr started successfully."