【问题标题】:Thin / Capistrano cannot connect to databaseThin / Capistrano 无法连接到数据库
【发布时间】:2023-03-03 22:06:01
【问题描述】:

我正在尝试设置我的 Ruby on Rails 应用程序以部署到瘦集群。当我使用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 Thin 任务:

  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

任何帮助将不胜感激

【问题讨论】:

    标签: ruby-on-rails capistrano thin


    【解决方案1】:

    我需要在每个步骤中明确设置 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?

    【讨论】:

      猜你喜欢
      • 2011-06-16
      • 2012-10-29
      • 1970-01-01
      • 2013-11-19
      • 2018-08-03
      • 2021-07-02
      相关资源
      最近更新 更多