capistrano rds => PG :: ConnectionBad:FATAL:数据库“deploy”不存在

时间:2017-09-26 16:11:40

标签: ruby-on-rails postgresql amazon-ec2 capistrano

我正在尝试通过capistrano从EC2实例连接RDS postgresql实例。

到目前为止,我一直做得很好,但是从昨天起它没有用。我找不到原因。我迫切需要别人的帮助。

我得到的错误信息是这些。

SSHKit::Runner::ExecuteError: Exception while executing as 
deploy@13.124.242.61: Exception while executing as 
deploy@13.124.242.61: rake exit status: 1
rake stdout: rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "deploy" does not exist

即使我已经为database.production.yml设置了正确的设置EC2实例仍在尝试连接本地postgresql。 当我从EC2实例本地输入'psql'命令时,我得到了同样的错误。

  

database.production.yml

default: &default
  adapter: postgresql
  encoding: utf8
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

production:
  <<: *default
  host: <%= ENV['DEPLOY_DATABASE_HOST'] %>
  port: <%= ENV['DEPLOY_DATABASE_PORT'] %>
  username: <%= ENV['DEPLOY_DATABASE_USERNAME'] %>
  password: <%= ENV['DEPLOY_DATABASE_PASSWORD'] %>
  database: <%= ENV['DEPLOY_DATABASE_DATABASE'] %>
  

的database.yml

default: &default
  adapter: postgresql
  encoding: utf8
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: deploy_development

test:
  <<: *default
  database: deploy_test

production:
  <<: *default
  host: <%= ENV['DEPLOY_DATABASE_HOST'] %>
  port: <%= ENV['DEPLOY_DATABASE_PORT'] %>
  username: <%= ENV['DEPLOY_DATABASE_USERNAME'] %>
  password: <%= ENV['DEPLOY_DATABASE_PASSWORD'] %>
  database: <%= ENV['DEPLOY_DATABASE_DATABASE'] %>
  

与部署相关的Gemfile

## Deploy
# Use Capistrano for deployment
gem 'capistrano-rbenv', '~> 2.0'
gem 'capistrano-rbenv-install', '~> 1.2.0'
gem 'capistrano-rails', group: :development
gem 'capistrano3-puma' , group: :development
gem 'capistrano-figaro-yml', '~> 1.0.2'
gem 'capistrano-upload-config'
gem 'capistrano3-nginx', '~> 2.0'
gem 'capistrano-rails-collection'
  

Capfile

# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'

# Include tasks from other gems included in your Gemfile
require 'capistrano/rbenv'
require 'capistrano/rbenv_install'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/puma'
require 'capistrano/figaro_yml'
require 'capistrano/upload-config'
require 'capistrano/puma/nginx'   # if you want to upload a nginx site template
require 'capistrano/nginx'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Nginx

require 'capistrano/rails/collection'

require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
  

配置/ deploy.rb

# config valid only for current version of Capistrano
lock "3.9.1"

set :application, "my_app_name"
set :repo_url, "git@github.com:gitstar/my_app_name.git"

# cap production deploy BRANCH=master
set :branch, ENV['BRANCH'] if ENV['BRANCH']

set :migration_role, :app

set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, File.read('.ruby-version').strip

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/deploy/apps/my_app_name'

# Default value for :scm is :git
# set :scm, :git

# Default value for :format is :airbrussh.
# set :format, :airbrussh

# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto

# Default value for :pty is false
set :pty, true

# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')

# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
# set :keep_releases, 5

before 'deploy:check:linked_files', 'config:push'
before 'deploy:starting', 'figaro_yml:setup'
after 'figaro_yml:setup', 'puma:nginx_config'

namespace :deploy do
  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end
end
  

配置/部署/ production.rb

server 'xx.xxx.xxx.xx', user: 'deploy', roles: %w{app db web}
set :nginx_server_name, 'xx.xxx.xxx.xx'

这些是我现在使用的文件。 任何意见或建议都会非常有用。

0 个答案:

没有答案