Can t call a task within a task

222 views
Skip to first unread message

Douglas Magnenat

unread,
Jan 27, 2014, 5:40:31 AM1/27/14
to capis...@googlegroups.com
Versions:
Ruby 2.1
Capistrano 3.1
Rake 10.1.1/ Rails 3.2.16 / etc

Platform:
Working on XUbuntu 12.04.4 LTS
Deploying to Debian Wheezy

I'm trying to create a basic task for copying and linking database.yml file into my app, but I'm totaly lost between Capistrano doc 2.x et 3.x and no explanation are given as how to program Capistrano task (except for 'DESC', and 'TAK' what reserved word to use, how do they work, where does capistrano words stops and where does ruby start).

This is my lib/capistrano/tasks/databases.cap file :

# Tâches pour mettre à jour fichier database.yml et lien pointant vers lui
namespace :db_access do


 
# Idea : https://github.com/capistrano/sshkit/blob/master/EXAMPLES.md
  desc
'Copy production database.yml from local workstation'
  task
:copy_production do
    on roles
:all do
      execute
:mkdir, '-p', "#{shared_path}/config"
      upload
! 'config/deploy/production.database.yml', "#{shared_path}/config/database.yml"
   
end
 
end


 
# Idea : http://stackoverflow.com/questions/9684649/capistrano-cant-deploy-my-database-yml
  desc
'Create database.yml symlinks to current release'
  task
:create_symlinks do
    on roles
:all do
     
# Copier la database.yml de production si elle n'existe pas.
     
unless test "[ -f #{shared_path}/config/database.yml ]"
        invoke
'db_access:copy_production'
     
end
      execute
:ln, "-nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
   
end
 
end
end


This is the ouput I got :

douglas@bilbo:/var/www/odpf$ cap production db_access:create_symlinks
DEBUG
[3f670dfd] Running /usr/bin/env [ -f /var/www/odpf/shared/config/database.yml ] on phisa-odpf-vd.vserver.nimag.net
DEBUG
[3f670dfd] Command: [ -f /var/www/odpf/shared/config/database.yml ]
DEBUG
[3f670dfd] Finished in 0.589 seconds with exit status 1 (failed).
cap aborted
!
undefined method `verbosity' for "/usr/bin/env db_access:copy_production\n":String
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/formatters/pretty.rb:10:in `
write'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:14:in `block in execute'

/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:13:in `tap'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:13:in `
execute'
/var/www/odpf/lib/capistrano/tasks/databases.cap:20:in `block (3 levels) in <top (required)>'

/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `
run'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'

Tasks: TOP => db_access:create_symlinks

I don't know how to invoke the other task. I inspirate myslef from https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/deploy.rake
I also tried without the 'invoke' keyword adn without ' ' signs.

This must be a simple syntaxe mistake but since I can't find a guide that explain that I don't know how to do.

Thanks for your helps

Douglas Magnenat

unread,
Jan 28, 2014, 5:44:42 AM1/28/14
to capis...@googlegroups.com
The problem comes from SSH-KIT which has a bug.
The problem is that Capistrano 3.1 is using ssh-kit version 1.3.
So we have to use Capistrano 3.0.1 until ssh-kit get fixed.

Workaround : 
gem uninstall capistrano
gem uninstall capistrano
-rails
gem uninstall sshkit
rm
Gemfile.lock

Modify Gemfile :
  gem 'capistrano', '~> 3.0.1'
  gem
'sshkit', '~> 1.0.0'

Install gems :
bundle install

Joshua Nicholson

unread,
Jan 29, 2014, 7:27:17 PM1/29/14
to capis...@googlegroups.com
If you follow that discussion chain, you'll see that there was a commit pushed for sshkit 1.3 that supposedly fixed the bug in question. However, either the fix doesn't work or rubygems still hasn't updated with the patched version over a month later. Not sure which is the case, as I haven't had a chance yet to pull down the github-hosted code and try it.

Douglas Magnenat

unread,
Feb 1, 2014, 12:29:19 PM2/1/14
to capis...@googlegroups.com
I tried with the code pulled down from the github-hosted, and the only things that changed is that I didn't get anymore an error message crashing the deploy.
However, it is still impossible to execute a task from within another capistrano's task. The sub-task is called though the sub-called task's instructions are not executed.

At leaste we can workaround with the following command now that we don't have anymore crash :
after :mytask, :mysubtask
Reply all
Reply to author
Forward
0 new messages