0

As I'm trying to deploy my RoR app through AWS Elastic Beanstalk Environment, I'm getting the following error on the console :

ERROR: [Instance: i-0c1d25d2a182d8424] Command failed on instance. Return code: 1 Output: (TRUNCATED)...ly and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/opt/rubies/ruby-2.5.0/bin/bundle:23:in `load'
/opt/rubies/ruby-2.5.0/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace). 
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Unsuccessful command execution on instance id(s) 'i-0c1d25d2a182d8424'. Aborting the operation.
ERROR: Failed to deploy application.  

The following is my configuration in the database.yml

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

And the following is the error as reported on the log :

  ++ export RUBY_ROOT=/opt/rubies/ruby-2.5.0
  ++ RUBY_ROOT=/opt/rubies/ruby-2.5.0
  ++ export RUBYOPT=
  ++ RUBYOPT=
  ++ export PATH=/opt/rubies/ruby-2.5.0/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
  ++ PATH=/opt/rubies/ruby-2.5.0/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
  +++ /opt/rubies/ruby-2.5.0/bin/ruby -
  ++ eval 'export RUBY_ENGINE=ruby;
  export RUBY_VERSION=2.5.0;
  export GEM_ROOT="/opt/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0";'
  +++ export RUBY_ENGINE=ruby
  +++ RUBY_ENGINE=ruby
  +++ export RUBY_VERSION=2.5.0
  +++ RUBY_VERSION=2.5.0
  +++ export GEM_ROOT=/opt/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0
  +++ GEM_ROOT=/opt/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0
  ++ ((  0 != 0  ))
  + cd /var/app/ondeck
  + su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb db:migrate' webapp
  `/home/webapp` is not a directory.
  Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
  + '[' false = true ']'
  + su -s /bin/bash -c 'leader_only bundle exec rake db:migrate' webapp
  `/home/webapp` is not a directory.
  Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
  rake aborted!
  PG::ConnectionBad: 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"?
  /opt/rubies/ruby-2.5.0/bin/bundle:23:in `load'
  /opt/rubies/ruby-2.5.0/bin/bundle:23:in `<main>'
  Tasks: TOP => db:migrate
  (See full trace by running task with --trace) (Executor::NonZeroExitStatus) 

Also, rake db:migrate works fine locally. I have no idea what could be going on here, for the database I tried to import a snapshot of an instance of the database I already had on AWS RDS, but I also tried to create a new database.

If you think if you have any idea of what could be hapening here, if would be really appreciated if you could let me know.

Thanks in advance.

Giulio Colleluori
  • 1,261
  • 2
  • 10
  • 16
  • It's possible that Postgres died on the Beanstalk EC2 instance. In [this](https://stackoverflow.com/questions/14225038/postgresql-adapter-pg-could-not-connect-to-server#answer-40383305) answer, for instance, the user tries to manually start `postgres`. Can you try adding a `.ebextension` config with the [command](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-commands), "postgres -D `which postgres`", to it, basically, to ensure `postgres` is up before your application starts? – progfan Mar 17 '18 at 07:35
  • Have you set the correct values for `RDS_HOSTNAME`, `RDS_PORT`? Can you connect the db in your EC2 instance? – Tai Mar 17 '18 at 08:19
  • @Tai where do I set such values? I though those were automatically passed by Elastic Beans. – Giulio Colleluori Mar 17 '18 at 21:36

1 Answers1

0

As your comment, I believe that you missed configurate RDS_* in Elastic Beanstalk. To fix that:

  1. To configurate all RDS_*, please follow this guideline here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-softwaresettings.html#environments-cfg-softwaresettings-console.
  2. Redeploy your application.
Tai
  • 1,244
  • 9
  • 11