34

We're using Capistrano/Webistrano (with Lee Hambley's railsless-deploy gem) to push our PHP application to production servers. I have some custom tasks that get run during various parts of the deploy process.

As an example, I have tasks that attempt to stop and restart a jetty solr instance. However, sometimes this bit fails during the deploy, so Capistrano rolls back the entire deploy and reverts back to the previous revision. This is a pain. :-)

I'd like to tell Capistrano to ignore the return result of these tasks, so if they fail, Capistrano continues on it's way and finishes the deploy anyway. It's very easy for me to ssh to the server after the fact and properly kill and restart the solr instance, rather than having to do a complete deploy again.

Here is some relevant parts of the deploy script:

before "deploy:symlink", :solr_kill
after "deploy:symlink", :solr_start, :solr_index

task :solr_kill do
    run "cd #{current_path}/Base ; #{sudo} phing solr-kill"
end

task :solr_start do
    run "cd #{current_path}/Base ; #{sudo} phing solr-start"
    run "sleep 10"
end

task :solr_index do
    run "#{sudo} #{current_path}/Base/Bin/app.php cron run solr_index_cron"
end

1 Answer 1

34

from the Capistrano Task docs there is a config you can add to if there is an error, to continue.

task :solr_start, :on_error => :continue do
    # your code here
end

Just add that to each task you want to ignore errors and continue. Though, the best possible thing is to see if you can figure out what is causing the failure and have the restart command be more robust to really restart it. I only say this, since when you try to hand off the script to someone else, they might not know exactly how to tell if it restarted correctly.

4
  • Thanks, Chris. My tasks are forever a work in progress, but this will help until I get a chance to slowly improve them to do better error handling. Feb 8, 2011 at 0:10
  • 7
    Is there another way of doing this? What if you want to stop on an error and inspect the state?
    – gak
    Dec 22, 2012 at 20:14
  • 38
    A way to inspect the state: run cap -d deploy. The -d is for "debug" which means Capistrano will pause before executing each task and ask you to continue or abort. When you get to the the command that you want debug simply don't answer the prompt, open a new terminal tab/window and SSH to your deployment server and do your debugging :) Sep 13, 2013 at 10:24
  • 3
    How can I do this for Capistrano v3? Dec 30, 2015 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.