Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano 3 doesn't create 'current' directory when I deploy my rails project

I'm trying to deploy my ruby on rails 4 project into my server with capistrano 3, but I get some errors.

First of all, when I do

cap production deploy:check

everything looks like OK! But when I do

cap production deploy

I got two errors:

DEBUG [e3cf53e3] Running [ -L /var/www/myapp/releases/20131026111326/public/assets ] on mydomain.com
DEBUG [e3cf53e3] Command: [ -L /var/www/myapp/releases/20131026111326/public/assets ]
DEBUG [e3cf53e3] Finished in 0.104 seconds with exit status 1 (failed).
DEBUG [304388e5] Running [ -d /var/www/myapp/releases/20131026111326/public/assets ] on mydomain.com
DEBUG [304388e5] Command: [ -d /var/www/myapp/releases/20131026111326/public/assets ]
DEBUG [304388e5] Finished in 0.104 seconds with exit status 1 (failed).

The last error I got is:

DEBUG [4e4c65ef]    rake aborted!
DEBUG [4e4c65ef]    Unknown database 'myapp_production'

So I thought that I should do

cap production deploy:migrate

But I got a different error: current directory doesn't exist...

I'm very lost. My configuration files are these:

production.rb

set :stage, :production

role :all, %w{[email protected]}

server 'mydomain.com', user: 'myuser', roles: %w{web app db}

  set :ssh_options, {
    keys: %w(/path/mykey.pem),
    forward_agent: true,
    auth_methods: %w(publickey)
  }

fetch(:default_env).merge!(rails_env: :production)

set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.0.0-p247'
 set :rake,           "rake" 
 set :rails_env,      "production" 
 set :migrate_env,    "" 
 set :migrate_target, :latest

Capfile

require 'capistrano/setup'

require 'capistrano/deploy'

require 'capistrano/rails'

require 'capistrano/rvm'

require 'capistrano/bundler'

Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

I'm using capistrano-bundler, capistrano-rvm and capistrano-rails in Gemfile

Thank you very much.

like image 968
EnriMR Avatar asked Oct 22 '25 05:10

EnriMR


2 Answers

Capistrano cannot create your database for you, the current symlink is never being created because you aren't completing a deploy.

The error you are seeing is because the database does not exist on the database server, it depends exactly on your server (postgresql, mysql, etc) but you'll need to go onto the database server and run something like:

CREATE DATABASE myapp;
# Something else, too you'll need to GRANT permissions 
# in the sql server for your production database user, 
# or change the database ownership.

Then you should be able to complete a deploy.

like image 80
Lee Hambley Avatar answered Oct 23 '25 21:10

Lee Hambley


In my case I was trying to stop unicorn before the setup is done. In unicorn script I had mentioned path of current directory, I removed those lines from deployment script and added back when setup is done.

Check if your deployment script have such cases.

like image 22
Datt Avatar answered Oct 23 '25 20:10

Datt