2

I have just worked my way through the book "Deploying Rails" and im stuck where capaistrano calls db:migrate.

I have set up two VMs - app und db - each of them separate working perfektly. The VM app ist hostin nginx/unicorn and the VM db ist hosting PostgreSQL. I can "vagrant ssh" into the VMs and every thing looks good.

This is my Vagrant file with the two VMs defined (I'm using Vagrant version 1.0.3):

Vagrant::Config.run do |config|

  config.vm.define :app do |app_config|
    app_config.vm.customize ["modifyvm", :id, "--name", "app", "--memory", "512"]
    app_config.vm.box = "lucid64_rb193_pp2719"
    app_config.vm.host_name = "app"
    app_config.vm.forward_port 22, 2200, :auto => true
    app_config.vm.forward_port 80, 8080
    app_config.vm.network :hostonly, "33.33.13.37"
    app_config.vm.share_folder "puppet", "/etc/puppet", "../log4job_ops"
  end

  config.vm.define :db do |db_config|
    db_config.vm.customize ["modifyvm", :id, "--name", "db", "--memory", "512"]
        db_config.vm.box = "lucid64_rb193_pp2719"
        db_config.vm.host_name = "db"
        db_config.vm.forward_port 22, 2201, :auto => true
        db_config.vm.forward_port 5432, 5432
        db_config.vm.network :hostonly, "33.33.13.38"
        db_config.vm.share_folder "puppet", "/etc/puppet", "../log4job_ops"
  end
end

As you can see, data sent to port 8080 is forwarded to port 80 an tghe app VM and that works very well.

As PostgreSQL listens to port 5432 i set up a port forwarding of 4532(Host)->4532(VM).

However, when running either "cap deploy:cold" or "cap deploy:migrate" it get this Error message (cap deploy:migrate):

  * executing `deploy:migrate'
  * executing "ls -x /var/log4job/releases"
    servers: ["localhost"]
    [localhost] executing command
    command finished in 37ms
  * executing "cd /var/log4job/releases/20120905140228 && bundle exec rake RAILS_ENV=production  db:migrate"
    servers: ["localhost"]
    [localhost] executing command
*** [err :: localhost] rake aborted!
*** [err :: localhost] could not connect to server: Connection refused
*** [err :: localhost] Is the server running on host "localhost" and accepting
*** [err :: localhost] TCP/IP connections on port 5432?
*** [err :: localhost] could not connect to server: Connection refused
*** [err :: localhost] Is the server running on host "localhost" and accepting
*** [err :: localhost] TCP/IP connections on port 5432?
*** [err :: localhost] 
*** [err :: localhost] Tasks: TOP => db:migrate => environment
*** [err :: localhost] (See full trace by running task with --trace)
    command finished in 4128ms
failed: "sh -c 'cd /var/log4job/releases/20120905140228 && bundle exec rake RAILS_ENV=production  db:migrate'" on localhost

Questions:

  1. What am i doing wrong?

  2. Is the "rake db:migrate" command running on the VM "app". I assume that, as the project source code is deployed to /var/log4job/releases/20120905140228

  3. If my assumtion at nr 2 above is correct, its no wonder that its not working. PostgreSQL is running on the VM "db". But how on earth do you set upp this type of service? Have i configured the database connection in database.yml wrong.

This is the production part of the database.yml:

production:
  adapter: postgresql
  template: template0
  username: log4jobuid
  password: log4jobpwd
  database: wl_prod
  host: localhost
  encoding: unicode
  port: 5432

Shure. It says it should listen to "localhost" ;-) but how do i configure it, to connect into the other VM (the "db" VM)?

Any hints are welcome! Thanks!

1 Answer 1

1

Ok, I got it!

The best way to find an answer, is to write down the question ;-)

The errors that I have made wre all in the database.yml

It should look like this:

production:
  adapter: postgresql
  template: template0
  username: log4jobuid
  password: log4jobpwd
  database: wl_prod
  host: 33.33.13.38
  encoding: unicode
  port: 5432

The IP-Adress for "host:" should be the IP-Adress stated in the Vagrant file for the DB VM:

db_config.vm.network :hostonly, "33.33.13.38"

Now we know, that you can connect from e.g. one VM "app" into another VM "db" using the IP-Adress of the VM.

You should also make shure, you state the correct database name, user and password for the database. In my case, i let puppet create the db, so i use the same settings on both sides (now ;-)

Not the answer you're looking for? Browse other questions tagged or ask your own question.