Thin / Capistrano无法连接到数据库

时间:2012-07-27 16:57:07

标签: ruby-on-rails capistrano thin

我正在尝试设置我的Ruby on Rails应用程序以部署到Thin集群。当我使用bundle exec thin start -C config/thin.yml手动启动服务器上的瘦群集时,一切正常。但是,当我通过Capistrano运行相同的命令时,它就会死掉并显示日志:

/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)

我很茫然,我使用capistrano脚本中定义的相同用户帐户登录服务器。

我的capistrano瘦任务:

  namespace :deploy do
    task :start do
      run "cd #{current_path}; bundle exec thin start -C config/thin.yml"
    end
    task :stop do
      run "cd #{current_path}; bundle exec thin stop -C config/thin.yml"
    end
    task :restart do
      run "cd #{current_path}; bundle exec thin restart -C config/thin.yml"
    end
  end

这是我的thin.yml:

---
chdir: /var/www/rails/myapp/current
environment: staging
address: 0.0.0.0
port: 3000
timeout: 30
log: log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []
wait: 30
servers: 2
daemonize: true

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我需要在每一步中明确设置RAILS_ENV。

run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec thin start -C config/thin.yml"

似乎Capistrano没有拿起我们的环境变量

以下是相关帖子:

How to set environment variable for everyone under my linux system?