Connection refused - connect(2) for "freegeoip.net" port 80 - ruby-on-rails

Environment
Rails 4.0.4
Ruby 2.0.1
Geocoder gem
Issue
Today my app is down and I am not able to resolve the issue, in the log:
Errno::ECONNREFUSED (Connection refused - connect(2) for "freegeoip.net" port 80):
Looks like it's related so the Geocoder gem
Most bizarre if that the issue doesn't happen on development environment.
I have checked the freegeoip and looks like it's down, this said I am not sure why it should prevent my app from running
$ curl http://freegeoip.net
curl: (7) couldn't connect to host

How I resolved it
begin
#location = "#{request.location.city} #{request.location.country_code}"
rescue => e
# handle the error here
logger.debug "http://freegeoip.net must be down!"
logger.debug e.message
end

Related

Why does Rails Postgresql not allow me to start my rails app?

I am currently trying to deploy my Rails application through Heroku. In order to do so, I needed to switch to postgresql from sqlite3. I did so and tried test running the app by doing "rails s." However, I get the following error on my browser:
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
It also shows that the error occurred here:
### Convenience alias for PG::Connection.new.
def self::connect( *args )
return PG::Connection.new( *args ) <<< (error in this line)
end
Any help would be appreciated. Thanks!
Depending on how Postgres is installed, sounds like you need to restart Postgres.
Using brew:
brew services restart postgresql
Using asdf:
pg_ctl stop
pg_ctl start
Sometimes you might need to reinstall the pg gem.

PG::ConnectionBad error while trying to run sidekiq server on a rails app on Windows

I am using Windows for my development.
Here is the error I get while starting up the sidekiq server for this Rails application using Postgres RDS on AWS:
PG::ConnectionBad: timeout expired
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sequel-4.36.0/lib/sequel/adapters/postgres.rb:243:in 'initialize'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sequel-4.36.0/lib/sequel/adapters/postgres.rb:243:in 'new'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sequel-4.36.0/lib/sequel/adapters/postgres.rb:243:in 'connect'
I checked the Postgres server logs on AWS and it says:
[12826]:LOG: could not accept SSL connection: Connection reset by peer"
My gemfile is using Sequel and sequel_pg. I'm not sure if they are causing the error.
Same Postgres database connections work fine on another Rails application without Sidekiq.
I'm not sure if sidekiq is preloading the app and then forking, but if so, you want to make sure you disconnect the Sequel database connections before forking.

Unable to connect postgres server

When I try to connect server to create database. I am getting this error.
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "socket"=>"/var/run/postgresql/.s.PGSQL.5432", "pool"=>5, "min_messages"=>"error", "database"=>"rails_contributors_test"}
-- enable_extension("plpgsql")
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I tried a lot but didn't get success. Looking for help.
Postgres version I have as
which postgres
=> /usr/local/bin/postgres
postgres --version
=> postgres (PostgreSQL) 9.4.4
Try installing Postgres.app on your Mac OSX.
and start the postgres i.e. click on Open psql.
Then, restart the rails server.
After this, it should fix your issue.
Update (If the above does not work)
To fix the issue, remove the PID file. Find the postgres data directory. On Mac OSX using homebrew it is /usr/local/var/postgres/.
To make sure this is the problem, look at the log file (server.log). On the last lines you will see: FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?
If so, rm postmaster.pid
Restart your server. On Mac OSX, do:
launchctl unload homebrew.mxcl.postgresql.plist
launchctl load -w homebrew.mxcl.postgresql.plist

How do I setup ElasticSearch and Searchkick on my Nitrous.io box?

I've added the searchkick gem to my GEMFILE and I also installed ElasticSearch 1.0 with Autoparts. I'm still getting a connection refused message though when I attempt to reindex one of my models. I'm thinking it is possibly because my elasticsearch server hasn't been started. I'm unsure how to start it though on Nitrous.io. Below is the command I'm attempting to run and the error message I'm receiving...
Command
rake searchkick:reindex CLASS=Player
Result
rake aborted!
Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9200
...
So as silly as this is... I just thought to try and type elasticsearch in my Console of Nitrous.io and that command started my elasticsearch server and then I was able to proceed. Thanks to anyone that had looked into the issue with me!

Connection refused - connect(2) (Errno::ECONNREFUSED)

I am developing a spree application ,I recently removed and reinstalled ruby 1.9.3, now whenever I try rails s on terminal I get the following error :
/home/swapnil/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
Try this one : rake sunspot:solr:start
Look at this issue.I guess it may be helpful to you.
sunspot_rails gem - " Errno:: ECONNREFUSED (Connection refused - connect (2)) "
You just need configure your Database connection in your database.yml and launch your SQL server with this configuration

Resources