-1

I'm trying to get a basic rails app working with Postgres using Amazon Opsworks. Opsworks lacks built-in support for Postgres at the moment, but I'm using some cookbooks that I've found which seem to be well written. I've forked them all to my custom cookbooks at: https://github.com/tibbon/custom-opsworks-cookbooks

Anyway, where I'm stuck at the moment is getting the ip address of the master postgres database into the database.yml file. It seems that there should be multiple back-ends specified, kinda like how my haproxy server sees all the rails servers as 'backends'.

Has anyone gotten this working?

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
tibbon
  • 1,018
  • 2
  • 16
  • 30

2 Answers2

4

I had to add some custom JSON to my Rails layer.

Looked like this:

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

I believe you have to define a custom recipe that updates the database.yml and restarts the app server.

In this guide the same thing is done using a redis server as an example:

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

I haven't tested this for myself yet but I believe I will soon, I'll try to update this answer as soon as I do.

Paulo Casaretto
  • 967
  • 10
  • 33