Search code examples
ruby-on-railscapistranosqlite3-ruby

Capistrano Rails app SQLite3 Cannot open Database


I've managed to get a Rails app deployed with Capistrano to a server running NGinx & Passenger. On deploy I was getting the "We're sorry, something went wrong" message & was rather confused as the production log was blank. I then switched the rails_env to development in my NGinx Conf & now I'm getting:

SQLite3::CantOpenException

unable to open database file
Rails.root: /www/testcap/releases/20120407015032

I logged into the server, into the current folder within testcap (which I believe symlinks to the latest release) and ran rake db:create, however the db files exist. Having looked within the app's db folder I see both development.db & test.db.

If I run rails s -e production and then head to myurl.com:3000 the app works completely fine, which is weird, and it also works fine when I run rails s -e development too.

I'm at a complete loss as to what the issue might be here. I'm sure it must be a relatively obvious issue, potentially with capistrano? I'm still new to it so I could well have missed anything but googling so far has been fruitless.

The only thing I can think of is that I've nothing explicitly relating to databases in my config/deploy.rb ? However I've not been able to find any guides on the net to help out thus far.

Thanks in advance for your help :)

Jack.


Solution

  • Thanks to the comments from Adam P & Ben L above, I managed to make some head way on this. This Guide also solved my issue.

    I followed the steps in that guide above and in my database.yml file I changed the path to the production db from:

    `db/production.sqlite3`
    

    To

    `/www/testcap/shared/db/production.sqlite3` 
    

    (eg the absolute path)

    I then added this to my config/deploy.rb:

    role :db, "{my vps IP}", :primary => true
    

    On my VPS I went into the nginx conf & removed the line rails_env development (Passenger then sets it to production by default).

    And then ran cap deploy followed by cap deploy:migrate, which worked, and I get the app displayed when I visit the URL.

    I hope this might help someone out in the future stuck on the same issue :)

    Jack.