I already have a deploy.rb that can deploy my app on my production server.
My app contains a custom rake task (a .rake file in the lib/tasks directory).
I'd like to create a cap task that will remotely run that rake task.
I already have a deploy.rb that can deploy my app on my production server.
My app contains a custom rake task (a .rake file in the lib/tasks directory).
I'd like to create a cap task that will remotely run that rake task.
...couple of years later...
Have a look at capistrano's rails plugin, you can see at https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/migrations.rake#L5-L14 it can look something like:
This worked for me:
Then simply run
cap production "invoke[task_name]"
Previous answers didn't help me and i found this: From http://kenglish.co/run-rake-tasks-on-the-server-with-capistrano-3-and-rbenv/
to run your task use
Maybe it will be useful for someone
Found it with Google -- http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
The
RAILS_ENV=production
was a gotcha -- I didn't think of it at first and couldn't figure out why the task wasn't doing anything.Use the
capistrano-rake
gemJust install the gem without messing with custom capistrano recipes and execute desired rake tasks on remote servers like this:
Full Disclosure: I wrote it
Here's what I put in my deploy.rb to simplify running rake tasks. It's a simple wrapper around capistrano's run() method.
Then I just run any rake task like so: