Search code examples
capistrano

How do you add some steps to a capistrano task?


I'd like to stop some processes before running the deploy:migrate task. I know that I can redefine the deploy:migrate task by copying the existing code and adding the stop/start steps at the beginning and end of the task.

I'm wondering if there is a way to avoid copying the code from the default deploy:migrate task in my version of the task. Is there a way to refer to the existing deploy:migrate task when defining a new task of the same name?


Solution

  • Rather than redefining deploy:migrate, you should define a before or after hook for it. First, create a new task that does the stuff you need to do:

    task :custom_name do
      # whatever you need to do
    end
    

    And then set this new task to be run before or after the deploy:migrate task by doing one of the following:

    before "deploy:migrate", :custom_name
    after "deploy:migrate", :custom_name