0

我正在尝试使用 Amazon Opsworks 获得与 Postgres 一起使用的基本 Rails 应用程序。Opsworks 目前缺乏对 Postgres 的内置支持,但我正在使用一些我发现的似乎写得很好的食谱。我已经将它们全部分叉到我的自定义食谱中:https ://github.com/tibbon/custom-opsworks-cookbooks

无论如何,我现在卡住的地方是将主 postgres 数据库的 IP 地址放入 database.yml 文件中。似乎应该指定多个后端,有点像我的 haproxy 服务器如何将所有 rails 服务器视为“后端”

有没有人得到这个工作?

4

2 回答 2

4

我不得不向我的 Rails 层添加一些自定义 JSON。

看起来像这样:

{
  "deploy": {
    "my-app-name": {
      "database": {
        "adapter":"mysql2",
        "host":"xxx.xx.xxx.xx"
      }
    }
  }
}
于 2013-05-27T00:32:02.790 回答
1

我相信您必须定义一个自定义配方来更新 database.yml 并重新启动应用服务器。

本指南中,使用 redis 服务器作为示例完成了相同的操作:

node[:deploy].each do |application, deploy|
  if deploy[:application_type] != 'rails'
    Chef::Log.debug("Skipping redis::configure as application #{application} as it is not an Rails app")
    next
  end

  execute "restart Rails app #{application}" do
    cwd deploy[:current_path]
    command "touch tmp/restart.txt"
    action :nothing
    only_if do
      File.exists?(deploy[:current_path])
    end
  end

  redis_server = node[:opsworks][:layers][:redis][:instances].keys.first rescue nil

  template "#{deploy[:deploy_to]}/current/config/redis.yml" do
    source "redis.yml.erb"
    mode "0660"
    group deploy[:group]
    owner deploy[:user]
    variables(:host => (node[:opsworks][:layers][:redis][:instances][redis_server][:private_dns_name] rescue nil))
    notifies :run, resources(:execute => "restart Rails app #{application}")

    only_if do
      File.directory?("#{deploy[:deploy_to]}/current")
    end
  end
end

我还没有为自己测试过这个,但我相信我会很快,我会尽快更新这个答案。

于 2013-10-17T21:06:02.817 回答