"无法连接到服务器:没有这样的文件或目录"在使用beanstalk部署Rails应用程序时

Ami*_*tel 5 deployment postgresql amazon-web-services ruby-on-rails-3 amazon-elastic-beanstalk

在部署应用程序时Rails 3.2.17,我们遇到以下错误.

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
Run Code Online (Sandbox Code Playgroud)

这是我们的database.yml配置

 production:
  adapter: postgresql
  database: <%= ENV['RDS_DB_NAME'] %>
  username: <%= ENV['RDS_USERNAME'] %>
  password: <%= ENV['RDS_PASSWORD'] %>
  host: <%= ENV['RDS_HOSTNAME'] %>
  port: <%= ENV['RDS_PORT'] %>
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,我们能够启动rails控制台,并且我们还验证了所有上述环境变量都返回正确的值.

并且还能够通过psql与以下命令连接 psql -h RDS_HOSTNAME -d RDS_DB_NAME -U RDS_USERNAME

小智 1

就我而言,问题是由于我删除了我的.elasticbeanstalk/optionsettings,所以RACK_ENV没有定义,AWS 默认设置它,production这导致我的应用程序具有错误的数据库主机名。

我通过添加echo语句进行 /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh调试RACK_ENV,发现它是空的。