Thin / Capistrano cannot connect to database

2019-08-05 14:37发布

问题:

I'm trying to setup my Ruby on Rails application to deploy to a Thin cluster. When I manually start the thin cluster on the server using bundle exec thin start -C config/thin.yml everything works fine. However when I run the same command via Capistrano it just dies and the log displays:

/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)

I'm at a loss, I log into the server using the same user account as defined in the capistrano script.

My capistrano Thin tasks:

  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

Here is my 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

Any help would be appreciated

回答1:

I needed to explicitly set the RAILS_ENV on each step.

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

It doesn't seem that Capistrano is picking up our environment variable

Here is a related post:

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