elasticsearch-rails: Connection Refused error

Sorry, I prefer to not post this here, but we’re stuck on deployment and pretty desperate. After deployment, I’m trying to build the elasticsearch indexes via this comment:

bundle exec rake environment elasticsearch:import:model CLASS='User' FORCE=true RAILS_ENV=production

And it’s producing this error:

[!!!] Error when deleting the index: Faraday::ConnectionFailed
Connection refused - connect(2)
[!!!] Error when creating the index: Faraday::ConnectionFailed
Connection refused - connect(2)
rake aborted!
Connection refused - connect(2)
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/rack-mini-profiler-0.1.31/Ruby/lib/patches/net_patches.rb:7:in `block in request_with_mini_profiler'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/rack-mini-profiler-0.1.31/Ruby/lib/mini_profiler/profiling_methods.rb:40:in `step'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/rack-mini-profiler-0.1.31/Ruby/lib/patches/net_patches.rb:6:in `request_with_mini_profiler'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/http/faraday.rb:21:in `block in perform_request'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/base.rb:187:in `call'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/base.rb:187:in `perform_request'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/client.rb:102:in `perform_request'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/elasticsearch-api-1.0.1/lib/elasticsearch/api/actions/bulk.rb:81:in `bulk'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-527e2075ae81/elasticsearch-model/lib/elasticsearch/model/importing.rb:78:in `block in import'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-527e2075ae81/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb:88:in `block in __find_in_batches'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation/batches.rb:75:in `find_in_batches'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/activerecord-deprecated_finders-1.0.3/lib/active_record/deprecated_finders/relation.rb:70:in `find_in_batches'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/querying.rb:8:in `find_in_batches'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-527e2075ae81/elasticsearch-model/lib/elasticsearch/model/proxy.rb:80:in `method_missing'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-527e2075ae81/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb:86:in `__find_in_batches'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-527e2075ae81/elasticsearch-model/lib/elasticsearch/model/importing.rb:77:in `import'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-527e2075ae81/elasticsearch-model/lib/elasticsearch/model.rb:113:in `import'
/home/deployer/apps/controltec/shared/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-527e2075ae81/elasticsearch-rails/lib/elasticsearch/rails/tasks/import.rb:59:in `block (3 levels) in <top (required)>'
Tasks: TOP => elasticsearch:import:model
(See full trace by running task with --trace)

After the failure, elasticsearch is shutdown, and does not respond to attempts to revive it. The database is hosted on AWS, and not on the local server. I’m not sure if this has anything to do with it.

sudo service elasticsearch status # elasticsearch is not running
sudo service elasticsearch start # Starting Elasticsearch
sudo service elasticsearch status # elasticsearch is not running

This is how I’m installing elasticsearch via a capistrano task.

    run "#{sudo} apt-get update"
    run "#{sudo} apt-get install openjdk-7-jre-headless -y"
    run "wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.deb"
    run "#{sudo} dpkg -i elasticsearch-1.0.1.deb"

I know this sounds like an elasticsearch issue, but I was hoping someone could offer some clues.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

Just another note about installing the ES Debian package. Not only does it not automatically start after you install it, but it also doesn’t symlink to the /etc/rc*.d directories to automatically start up after a system reboot. You have to do it manually:

sudo update-rc.d elasticsearch defaults 95 10

Might want to add that to your cap provisioning task.

Hmm, so first, thing, the error is simply saying that Elasticsearch is not running, or your app cannot connect to it.

I’m not sure Capistrano is the best way how to install ES on the server, but it will do the trick. Note, that by default the service is not started when you dpkg-install it.

So, my first advice would be to log into the AWS instance by SSH, and checking if ES is correctly installed and can be started, and if it’s running.

You mention net-ssh, and yeah, I suspect there might be the issue that Capistrano kills the process after it exits.

Lastly, don’t worry, it’s fine to ask a question like this here. On the mailing list or IRC you’ll get more eyeballs though…