由于Ryan Bates在Railscasts上部署到VPS剧集,我在VPS上运行了一个演示Rails应用程序。在我的服务器上,我创建了一个像/home/username/apps
这样的目录结构,应用程序已部署到/home/username/apps/appname.
在应用程序名称文件夹中,还有另外三个由Ryan脚本创建的文件夹(我推测)
current releases shared
和current
文件夹内部是通常的Rails目录。如果我进入current
文件夹并运行rails c
或rake db:seed
我收到错误
configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
从共享目录
触发 apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters
我发现这是一个不寻常的错误,因为演示应用程序(脚手架)正在保存新创建的条目并列出它们,所以我假设我正在尝试运行rake和rails控制台有什么问题命令而不是我的适配器声明有问题。
你能告诉我它可能是什么吗?
请注意,已经有一个问题database configuration does not specify adapter处理这个一般性主题,但是,这个问题的答案似乎是处理数据库根本不工作的情况,但是,在我的情况下似乎事实并非如此。因此,我将这个问题与该线程区分开来。
这是我的database.yml文件
production:
adapter: postgresql
encoding: unicode
database: dodeploy_production
pool: 5
host: localhost
username: michael
password: secretpassword
这是Ryan用来部署的脚本。我包括它,因为这里可能有一些信息可以帮助你理解我所缺少的东西。
require "bundler/capistrano"
server "198XXXX", :web, :app, :db, primary: true
set :application, "dodeploy"
set :user, "michael"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git@github.com:Username/appname.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
错误
当我运行rails c
(或rake db:seed
)时,我得到了这个
home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/connection_specification.rb:30:in `spec'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_handling.rb:39:in `establish_connection'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/railtie.rb:170:in `block (2 levels) in <class:Railtie>'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/base.rb:322:in `<module:ActiveRecord>'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/base.rb:22:in `<top (required)>'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `block in require'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:213:in `load_dependency'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/railtie.rb:61:in `block in <class:Railtie>'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `call'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `block in run_console_blocks'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `each'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `run_console_blocks'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/application.rb:264:in `block in run_console_blocks'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/engine/railties.rb:17:in `each'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/engine/railties.rb:17:in `each'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/application.rb:264:in `run_console_blocks'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/engine.rb:431:in `load_console'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:51:in `initialize'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:9:in `new'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:9:in `start'
from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands.rb:66:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
更新
我不确定为什么Ryan在Railscast中创建了database.example.yml。他没有配置它,我只是在添加用户名和密码之前将其保留为原始database.yml文件的副本。
database.example.yml
development:
adapter: postgresql
encoding: unicode
database: dodeploy_development
pool: 5
password:
test:
adapter: postgresql
encoding: unicode
database: dodeploy_test
pool: 5
password:
production:
adapter: postgresql
encoding: unicode
database: dodeploy_production
pool: 5
password:
这是nginx.conf文件
upstream unicorn {
server unix:/tmp/unicorn.dodeploy.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/michael/apps/dodeploy/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
更新
这是来自connection_specification.rb的方法
def resolve_hash_connection(spec) # :nodoc:
spec = spec.symbolize_keys
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter"
begin
require path_to_adapter
rescue Gem::LoadError => e
raise Gem::LoadError, "Specified '#{spec[:adapter]}' for database adapter, but the gem is not loaded. Add `$
rescue LoadError => e
raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter in config/database.yml is$
end
adapter_method = "#{spec[:adapter]}_connection"
ConnectionSpecification.new(spec, adapter_method)
end
答案 0 :(得分:4)
我通过在运行命令时指定生产环境来实现它的工作
RAILS_ENV=production rails console
RAILS_ENV=production rake db:seed
我发现这个不寻常,因为该应用程序正在运行。