Just run a rake task without having to setup a special capistrano task.
Usage
cap rake_task:invoke COMMAND="db:migrate" #yes, its a silly example...
Setup
namespace :rake_task do task :invoke do if ENV['COMMAND'].to_s.strip == '' puts "USAGE: cap rake:invoke COMMAND='db:migrate'" else run "cd #{current_path} && RAILS_ENV=production sudo rake #{ENV['COMMAND']}" end end end
Handy! I got a cryptic “Syntax error: end of file unexpected” error on deployment, which I traced to calling the namespace `rake` (clashes with the capistrano command `rake`). Changing the namespace to ‘rake_task’ fixed this. I also modified your example to say `RAILS_ENV=#{rails_env}` instead of `RAILS_ENV=production` so that it will work on my staging server as well.
Handy! I got a cryptic “Syntax error: end of file unexpected” error on deployment, which I traced to calling the namespace `rake` (clashes with the capistrano command `rake`). Changing the namespace to ‘rake_task’ fixed this. I also modified your example to say `RAILS_ENV=#{rails_env}` instead of `RAILS_ENV=production` so that it will work on my staging server as well.
Thanks, updated it 🙂
Let me recommend the Cape gem for this purpose. It makes it possible to invoke any Rake task (including ones using arguments and environment variables) with a single line of configuration in your ‘config/deploy.rb’. Organizing Rake tasks (renaming, namespacing, filtering) is a snap with a straightforward DSL.