Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 将Postgresql与Amazon Opsworks结合使用-在database.yml中获取IP地址_Ruby On Rails_Amazon Web Services_Chef Infra_Rails Postgresql - Fatal编程技术网

Ruby on rails 将Postgresql与Amazon Opsworks结合使用-在database.yml中获取IP地址

Ruby on rails 将Postgresql与Amazon Opsworks结合使用-在database.yml中获取IP地址,ruby-on-rails,amazon-web-services,chef-infra,rails-postgresql,Ruby On Rails,Amazon Web Services,Chef Infra,Rails Postgresql,我正在尝试使用Amazon Opsworks获得一个与Postgres一起工作的基本rails应用程序。Opsworks目前缺乏对Postgres的内置支持,但我正在使用我发现的一些烹饪书,这些书似乎写得很好。我已经把它们都分给了我的定制食谱: 不管怎样,我现在陷入困境的地方是将master postgres数据库的ip地址输入database.yml文件。似乎应该指定多个后端,有点像我的haproxy服务器将所有rails服务器视为“后端” 有人用过这个吗 我不得不向Rails层添加一些自定义

我正在尝试使用Amazon Opsworks获得一个与Postgres一起工作的基本rails应用程序。Opsworks目前缺乏对Postgres的内置支持,但我正在使用我发现的一些烹饪书,这些书似乎写得很好。我已经把它们都分给了我的定制食谱:

不管怎样,我现在陷入困境的地方是将master postgres数据库的ip地址输入database.yml文件。似乎应该指定多个后端,有点像我的haproxy服务器将所有rails服务器视为“后端”


有人用过这个吗

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

看起来是这样的:

{
  "deploy": {
    "my-app-name": {
      "database": {
        "adapter":"mysql2",
        "host":"xxx.xx.xxx.xx"
      }
    }
  }
}

我必须向Rails层添加一些自定义JSON

看起来是这样的:

{
  "deploy": {
    "my-app-name": {
      "database": {
        "adapter":"mysql2",
        "host":"xxx.xx.xxx.xx"
      }
    }
  }
}

我相信您必须定义一个自定义配方来更新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

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

我相信您必须定义一个自定义配方来更新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
我还没有亲自测试过,但我相信我很快就会,我会尽快更新这个答案