Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Could not connect to server: No such file or directory" While deploying Rails app with beanstalk

While deploying an application with Rails 3.2.17, we are getting following error.

eb-commandprocessor.log

+ su -s /bin/bash -c 'leader_only bundle exec rake db:migrate' webapp
rake aborted!
could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/ondeck/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace) (ElasticBeanstalk::ActivityFatalError)
    at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:189:in `rescue in exec'
    ...
caused by: command failed with error code 1: /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh

Here is our database.yml configuration

 production:
  adapter: postgresql
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>

Surprisingly we are able to start rails console and we also verified that all above environment variables return correct value.

And also able to connect via psql with following command psql -h RDS_HOSTNAME -d RDS_DB_NAME -U RDS_USERNAME

like image 328
Amit Patel Avatar asked Nov 09 '22 17:11

Amit Patel


1 Answers

On my side the issue was coming from the fact that I deleted my .elasticbeanstalk/optionsettings and so RACK_ENV was not defined, AWS set it by default to production which led my application to have the wrong database hostname.

I debugged that by adding echo statement in /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh to display RACK_ENV and noticed it was empty.

like image 172
Sylvain Kalache Avatar answered Nov 14 '22 23:11

Sylvain Kalache