Rubber Rails PG::ConnectionBad not connect to EC2 - ruby-on-rails

After update to rubber 3.1.0 and using postgres 9.3 on a 3.2.22 rails app i'm trying to deploy on Ec2 is showing this on the log:
** [out :: app01.foo.com] PG::ConnectionBad: FATAL: no pg_hba.conf entry for host "172.35.45.216", user "foo", database "foo_production", SSL on
** [out :: app01.foo.com]
** [out :: app01.foo.com] FATAL: no pg_hba.conf entry for host "172.35.45.216", user "foo", database "foo_production", SSL off
someone got the same problem?

Related

Ruby on Rails Rake assets: precompile error - Connection Refused

I'm attempting to run a legacy Rails App using Rails 3.2.8 with Ruby 1.9.3:551 through RVM. I'm aiming to run it using Apache2 with Passenger as well.
Attempting to connect to the site leads to a Passenger error site. Looking through the logs, the issue seems to be with precompiling my assets. When I run bundle exec rake assets:precompile --trace, I get the error
**Invoke assets:precompile:all (first_time)
...
**Invoke tmp:cache:clear (first_time)
**Execute tmp:cache:clear
**Excute assets:precompile:primary
[ddtrace] (/usr/local/rvm/gems/ruby-1.9.3-p551/gems/ddtrace-0.26.0/lib/ddtrace/transport/http/clinet.rb:46:in 'rescue in send_request' Internal error during HTTP transport request. Cause: Connection refused - connect(2) Location: /usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:763:in 'initialize'
...
What could be causing this issue? I can't seem to find anything about it in ddtrace documentation.

Error when trying to deploy: The bundle currently has capybara locked at 2.2.1

I have a Ruby on Rails web application that I am trying to deploy.
When I try to deploy it, it gets a little ways, and then stops with the following error:
** [out :: rails-rn-dev.sandia.gov] You have requested:
** [out :: rails-rn-dev.sandia.gov] capybara = 2.1.0
** [out :: rails-rn-dev.sandia.gov]
** [out :: rails-rn-dev.sandia.gov] The bundle currently has capybara locked at 2.2.1.
I can't figure out how this is happening. I know that both my Gemfile and my Gemfile.lock files specify capybara version 2.1.0 be used.
So, why is the bundle locking capybara at 2.2.1?
Thanks in advance,
Tim

connection error with tire/elasticsearch remote server

I have installed a ubuntu 12.04 remote server with elasticsearch.
I have installed elasticsearch with:
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.6.deb
sudo dpkg -i elasticsearch-0.20.6.deb
sudo service elasticsearch start
I get with sudo elasticsearch status:
* ElasticSearch Server is running with pid 2483
My elasticsearch remote server is working fine:
ubuntu12#juan:~/Escritorio/myapp$ curl http:/111.111.111.111:9200
{
"ok" : true,
"status" : 200,
"name" : "Hogan, Harold \"Happy\"",
"version" : {
"number" : "0.20.6",
"snapshot_build" : false
},
"tagline" : "You Know, for Search"
}
or with my subdomain:
ubuntu12#juan:~/Escritorio/myapp$ curl http://elasticsearchserver.mydomain.com:9200
{
"ok" : true,
"status" : 200,
"name" : "Hogan, Harold \"Happy\"",
"version" : {
"number" : "0.20.6",
"snapshot_build" : false
},
"tagline" : "You Know, for Search"
}
I can restart, start and stop elasticsearhc server.
sudo service elasticsearch restart
* Stopping ElasticSearch Server [ OK ]
* Starting ElasticSearch Server [ OK ]
I have a tire.rb file in config/initializer/ folder with the next code:
if Rails.env == 'production'
Tire.configure do
url "http://elasticsearchserver.mydomain.com:9200"
end
end
This is my capistrano task to reindex:
after "deploy:finalize_update", "deploy:elasticsearch:index_classes"
namespace :deploy do
namespace :elasticsearch do
desc 'run elasticsearch indexing via tire'
task :index_classes do
run "cd #{deploy_to}/current && bundle exec rake environment tire:import CLASS=Object FORCE=true "
end
end
end
I'm using mongodb as database, so I have not make migrations before reindexing.
This is capistrano error:
2013-04-06 14:25:50 executing `deploy:elasticsearch:index_classes'
#
#
** [out :: 111.111.111.111] Skipping index creation, cannot connect to Elasticsearch
** [out :: 111.111.111.111]
** [out :: 111.111.111.111] (The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>)
** [out :: 111.111.111.111]
** [out :: 111.111.111.111] [IMPORT] Deleting index 'cvs'
** [out :: 111.111.111.111]
** [out :: 111.111.111.111] rake aborted!
** [out :: 111.111.111.111] Connection refused - connect(2)
** [out :: 111.111.111.111]
#
#
I have uploaded to production server the tire.rb file and I have tried:
bundle exec rake environment tire:import CLASS=Object FORCE=true
and I get the same result:
Skipping index creation, cannot connect to Elasticsearch
(The original exception was: #<Errno::ECONNREFUSED: Connection refused - connect(2)>)
[IMPORT] Deleting index objects'
rake aborted!
Connection refused - connect(2)
What am I doing wrong? How can I fix connection between tire/rails app and my elasticsearch server?
I think you just had the syntax wrong in your config/initializers/tire.rb,
see below
Tire.configure do
url "http://localhost:9200"
#you can uncomment the next line if you want to see the elasticsearch queries in their own seperate log
#logger "#{Rails.root}/log/es.log"
end
This is the syntax that it's working fine for me inside of tire.rb file
require 'tire'
Tire.configure { url "http://myremoteserver.com:9200" }
and now it's working fine!
Thank you!

Enabling hstore when deploying with rubber

I'm deploying a Rails app that uses PostgreSQL and HSTORE.
To deploy it, I'm ussing rubber.
Everything works, except for HSTORE not being properly enabled. When the migration that contains execute("CREATE EXTENSION hstore") runs, I get the following errors:
** [out :: production.---]
** [out :: production.---] -- execute("CREATE EXTENSION hstore")
** [out :: production.---]
** [out :: production.---] rake aborted!
** [out :: production.---] An error has occurred, this and all later migrations canceled:
** [out :: production.---]
** [out :: production.---] PG::Error: ERROR: permission denied to create extension "hstore"
** [out :: production.---] HINT: Must be superuser to create this extension.
The script that creates the postgres instance has this code:
create_user_cmd = "CREATE USER #{env.db_user} WITH NOSUPERUSER CREATEDB NOCREATEROLE"
so I think the problem might be related to the NOSUPERUSER attribute being set here.
Is there any way to enable hstore using rubber while keeping most of the generated files unchanged?
The problem is that rubber creates the DB user as NOSUPERUSER. My workaround is to create tasks that run before and after capistrano's deploy:migrate that will change the user to SUPERUSER and back.
Here's the code:
namespace :rubber do
namespace :project do
before "deploy:migrate", "rubber:project:add_pg_superuser_and_enable_hstore"
after "deploy:migrate", "rubber:project:remove_pg_superuser"
task :add_pg_superuser_and_enable_hstore,
:roles => [:postgresql_master, :postgresql_slave] do
alter_user_cmd = "ALTER USER #{rubber_env.db_user} SUPERUSER"
create_hstore_cmd = "CREATE EXTENSION IF NOT EXISTS hstore;"
rubber.sudo_script "add_superuser_create_hstore", <<-ENDSCRIPT
sudo -i -u postgres psql -c "#{alter_user_cmd}"
sudo -i -u postgres psql -c "#{create_hstore_cmd}"
ENDSCRIPT
end
task :remove_pg_superuser, :roles => [:postgresql_master,
:postgresql_slave] do
alter_user_cmd = "ALTER USER #{rubber_env.db_user} NOSUPERUSER"
rubber.sudo_script "add_superuser_create_hstore", <<-ENDSCRIPT
sudo -i -u postgres psql -c "#{alter_user_cmd}"
ENDSCRIPT
end
end
end
Another option is to not have a postgres superuser involved when deploying but create a template (or use the default one) and install the extension on the template. Then when you create a database it will have the extension installed.
Good answers here and here.

Error deploying to rbenv with Capistrano

I'm new to Capistrano and having trouble debugging an error. Searching suggests this error could be an environment issue of picking up the wrong version of ruby (it's almost certainly not the referenced file as it works fine in test). Using a Capistrano task to dump the ruby version everything looks fine. Running the commands directly on the server works fine, too. I'm using rbenv on the server.
The error:
* executing `deploy:assets:precompile'
* executing "cd /home/deployer/apps/happenate/releases/20120424002545 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["happenate.com"]
[happenate.com] executing command
** [out :: happenate.com] rake aborted!
** [out :: happenate.com] /home/deployer/apps/happenate/releases/20120424002545/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end
** [out :: happenate.com] ...sion_store :cookie_store, key: '_happenate_session'
** [out :: happenate.com] ^
Definitely some sort of ruby environment issue. After cleaning everything up with a proper rbenv environment, the error is gone.

Resources